0
IM使用本变形例中的代码来从拉Twitter的API的一些数据,并将结果设置为一个ViewModel模型不刷新与淘汰赛
var myModel = new MyViewModel();
// Handler for .ready() called.
function MyViewModel(){
this.show_search = ko.observable(true); // Message initially visible
this.show_player = ko.observable(false); // Message initially visible
this.tweetSearchKeyWord = ko.observable("google");
this.currentTweets = ko.observableArray([]);
this.showSearch = function(){
this.show_search(true);
this.show_player(false);
};
this.showPlayer = function(){
this.show_search(false);
this.show_player(true);
};
};
ko.computed(function() {
$.getJSON("http://search.twitter.com/search.json?q=%23" + myModel.tweetSearchKeyWord()+"&callback=?", function (data) {
theData = data.results;
myModel.currentTweets(theData);
});
}, viewModel);
ko.applyBindings(myModel);
数据被收到细内部ko.computed,和data.results显示阵列[15]
但i之后它与
myModel.currentTweets(theData);
myModel.currentTweets设置为模型反映为空数组[]
任何想法有什么不对?
你在调试吗?而是看看'myModel.currentTweets()' – 2013-02-24 00:35:30