KnockoutJS proper way to update observableArray AJAX

。_饼干妹妹 提交于 2019-12-04 06:41:12

An observableArray is really just a normal observable with some extra methods for array operations.

So, if you want to set the value of an observableArray to a new array, you can just do:

viewModel.items(myNewArray)

The mapping plugin can help you update the existing items in an array with any updates. In this case, your UI will only be updated from any differences.

Venkat

I know I'm way too late on this one as I found myself stuck in this situation just recently. We can use a simple Javascript util function as a work-around.

If you have already marked _model.incidents as observableArray, you can do something like this when binding the returned JSON data:

eval("_model.incidents("+JSON.stringify(json)+");");

It worked for me. Hope you have created your observable like this:

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