KnockoutJS: How to add one observableArray to another?

北城余情 提交于 2019-12-04 15:37:32

There are a few things going on here:

1) You are using the 'optionsValue' binding, so selectedItems is just going to contain a list of ids

2) arrayPushAll works with "native" arrays, not observableArrays. You can still make this work by using the self.addedItems() and self.selectedItems() forms, but you will then need to call self.addedItems.valueHasMutated() to let subscribers know of the changes.

3) removeAll takes in a "native" array parameter, not an observableArray.

Here is a final fiddle that works:

http://jsfiddle.net/jearles/6H2PK/8/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!