我有一个演示application,其中有一个数组,其中所有元素都是可观察的。在这个应用程序中,我有一个模拟来自服务器的调用的函数-获得绑定到列表的相同数组,但有一项发生了变化。这是我实现它的方式:
this.serverDataSimulation=function(){
aArray[Math.floor((Math.random() * 10) + 0)].name=Math.floor((Math.random()
* 2000) + 1000);
ko.mapping.fromJS(aArray, this.allItems);
}aArray是从服务器获取的数据的模拟,我使用ko.mapping将其绑定到列表。问题是,这样会重新呈现整个列表,而不是只更新一个项目。我仍然希望数组的所有元素在重新绑定之后和重新绑定之前都是可见的。有没有办法解决这个问题,或者有更好的实现?
发布于 2017-06-10 02:50:40
试试这个:
this.serverDataSimulation=function(){
var selectedItem = this.allItems()[Math.floor((Math.random() * 10) + 0)];
selectedItem.name(Math.floor((Math.random() * 2000) + 1000));
}http://jsfiddle.net/Jorgelig/GSvnh/5897/
https://stackoverflow.com/questions/44464661
复制相似问题