我有一个 ViewModel,它有一个像这样的下拉列表:
<select data-bind="options: orderDropdown,
value: selectedOrder,
optionsCaption: '---',
event: { change: loadOrderDetails }">
</select>
然后loadOrderDetails
设置如下:
// loads details of selected order
self.loadOrderDetails = function () {
$.ajax({
url: "/api/OrderDetails",
data: { id: self.selectedOrder() },
type: "GET",
success: function (data) {
self.orderDetails(data);
}
});
}
问题是,当我在控制台中查看时,这个事件似乎在页面加载时触发:
GET http://localhost:52559/api/OrderDetails 400 (Bad Request)
知道如何防止它在页面加载时触发吗?