我有嵌套的可观察数组的 Knockout.js 视图模型。
function ParentVM(data) {
var self = this;
self.childs= ko.observableArray([]);
ko.mapping.fromJS(data, mapping, this);
}
function ChildVM(data) {
var self = this;
self.propertyA = ko.observableArray([]);
self.propertyB = ko.observable();
ko.mapping.fromJS(data, mapping, this);
}
function GrandChildVM(data) {
var self = this;
self.propertyX = ko.observable();
self.propertyY = ko.observable();
self.propertyZ = ko.observable();
ko.mapping.fromJS(data, mapping, this);
}
我有以下绑定:
data-bind="value: propertyX, valueUpdate: 'keydown'"
现在,当这些属性发生变化时,如何添加事件处理程序来调用我的 REST 端点来更新视图模型状态?