Reputation: 41
Is there any way to trigger an onchange event when the value is data bound by knockout?
I built/populated a model within a C# controller... then in the view:
var model = JSON.parse('@Html.Raw(Json.Encode(Model))');
var viewModel = new catalogDetailViewModel(model);
// extend your view-model with pager.js specific data
pager.extendWithPage(viewModel);
// apply the view-model using KnockoutJS as normal
ko.applyBindings(viewModel);
// start pager.js
pager.start();
I bind a textbox (which will be eventually a hidden input):
<input type="text" id="shoppingCartStyleCatalogID" data-bind="value:styleCatalogID" onchange="GetItemSizes(this.value)" />
But it is not triggering the onchange event... I can watch the value change in dev tools but nothing gets triggered.
Upvotes: 0
Views: 316
Reputation: 8987
You could also subscribe to the styleCatalogID observable as follow :
viewModel.styleCatalogID.subscribe(GetItemSizes);
Upvotes: 0