Javascript 过滤耳环的问题
我需要创建一个新的数组,它只包含值“pos”等于零或更大的项。我的对象源数组:Javascript 过滤耳环的问题,javascript,knockout.js,Javascript,Knockout.js,我需要创建一个新的数组,它只包含值“pos”等于零或更大的项。我的对象源数组: self.appendableData = ko.observableArray([ {text: "some text 1", pos: -1}, {text: "some text 2", pos: 0}, {text: "some text 3", pos: 1}, ]); 试图过滤它 self.appendableDataToView = ko.computed(function (
self.appendableData = ko.observableArray([
{text: "some text 1", pos: -1},
{text: "some text 2", pos: 0},
{text: "some text 3", pos: 1},
]);
试图过滤它
self.appendableDataToView = ko.computed(function () {
return ko.utils.arrayFilter(self.appendableData(), function (item) {
return item.pos >= 0;
});
});
结果:空数组
console.log(self.appendableDataToView())
[];
=(您需要
appendeabledata
作为变量
self.appendableData = ko.observableArray();
self.appendableData() = ko.observableArray();
而不是