只是想创建我的第一个自定义绑定处理程序:
<input data-bind="value:firstName,valueUpdate:'afterkeydown'" type="text" />
<button data-bind="myhandler: firstName" ></button>
ko.bindingHandlers.myhandler =
{
update: function (element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor);
$(element).css("background", "red");
console.log('update');
}
}
var vm = function () {
this.firstName = ko.observable('bert');
}
ko.applyBindings(new vm());
问题是,当我更新值时,它不会触发“更新”。我只在启动时触发?这是 jsfiddle 链接:http: //jsfiddle.net/dingen2010/c43hu/2/