用新数据替换observableArray [英] replace observableArray with new data
本文介绍了用新数据替换observableArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的viewmodel
I have a viewmodel like
AppViewModel = {
agent : ko.observableArray([ {
name : 'test',
age : '23'
}])
};
我的json数据就像
{"agent":[{"name":"john","age":"23"},{"name":"conor","age":"23"}]}
对于ajaxcall来说,每3秒钟
for ajaxcall evry 3 sec
如何用新数据替换视图模型
How to replace the view model with new data
我尝试了
success : function(responseData) {
var data = ko.toJS(responseData);
//AppViewModel.agent.push(data);
AppViewModel.agent.replace(agent,data);
}
但不起作用.
推荐答案
所有您需要做的就是设置可观察的
All you have to do is set the observable
success : function(responseData) {
var data = ko.toJS(responseData);
AppViewModel.agent(data.agent);
}
这篇关于用新数据替换observableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文