代码如下: EmployeeModel 是viewModel,问题是当我改变一个项目的属性时——employees (obs 数组)中的deletedFlag,deletedItems 没有更新。
我怎样才能解决这个问题?
function Employee(data) {
this.employeid = ko.observable(data.employeid);
this.name = ko.observable(data.name);
this.isactive = ko.observable(data.isactive);
this.deletedFlag = ko.observable(false);
}
var EmployeeModel = function () {
var self = this;
self.employees = ko.observableArray([]);
self.deletedItems = ko.computed(function () {
return ko.utils.arrayFilter(self.employees(), function (item) {
return item.deletedFlag == true;
});
}, this);
}
编辑:以下代码将数组中的一项标记为删除
self.removeEmployee = function (employee) {
employee.deletedFlag(true);
};