我的 viewModel 上有一个方法,如下所示:
self.search = function () {
$.ajax({
url: "/api/SearchCustomers",
data: { id: self.custTerm },
type: "GET",
success: function (data) {
self.customers(data);
}
});
}
如果该方法已使用 knockoutvisible
属性调用,我想做的是显示一个元素。那可能吗?
我已经将该方法附加到一个按钮上,如下所示:
$(document).ready(function () {
var viewModel = new SearchCustomerViewModel();
ko.applyBindings(viewModel);
$("#btnSearch").click({ handler: viewModel.search });
});
我试过了,但没有用:
<div data-bind="visible: search">
<strong><span data-bind="text: customersToShow().length"></span></strong>
<span data-bind="">customers</span> found.
<p>
<label>
Exclude Closed Accounts:
<input data-bind="checked: excludeClosedAccs" type="checkbox" /></label>
</p>
</div>