简体   繁体   English

remove不是可观察数组中的函数

[英]remove is not a function in observable array

I made an observableArray in knockoutjs and I want to remove items from that array and tried as 我在基因敲除js中创建了一个observableArray,我想从该数组中删除项目并尝试

self.work_days = ko.observableArray();

self.work_days().push(new WorkDayVM({}, date))
//WorkDayVM is a view model and date is date object this works fine and values are //assigned well in array.

But when trying to remove as 但是当尝试删除为

self.work_days.remove(days_to_remove[i]);
//also tried as self.work_days().remove(days_to_remove[i]);

I also tried as 我也尝试过

for(var i = 0; i < days_to_remove.length; i++){
 self.work_days.remove(function(item){
   return item.work_days.day_string == days_to_remove[i].day_string;
 });
}

But I always get the same error 但是我总是得到同样的错误

self.work_days().remove is not a function
self.work_days().remove is not a function

Try calling .remove() (and .push()) directly on observableArray instead of trying to call it on the array value. 尝试直接在observableArray上调用.remove()(和.push()),而不是尝试在数组值上调用它。 self.work_days.remove instead of self.work_days().remove self.work_days.remove instead self.work_days().remove

http://jsfiddle.net/NNU77/ http://jsfiddle.net/NNU77/

self.work_days()。push(new WorkDayVM({},date))应该是self.work_days.push(new WorkDayVM({},date))),然后删除而不带()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM