更改数组时刷新,但是;
这不是刷新,也不是在init中加载。
json部分在这里;
$.getJSON( "/echo/json/")
.done(function( json ) {
$.each(json.data.data, function(i, item){
console.log(item.name); // json Item
data.push(JSON.stringify(item)); // I push the json item in array
console.log(data); //array
})
})
谢谢大家
答案 0 :(得分:1)
看看这里:
你的getAttachments()函数应该只更新observable数组的内容:
ajax电话:
$.post( "/echo/json/", "{}")
.done(function( json ) {
self.attachments([]);
$.each(data, function(i, item){
console.log(item.name); // json Item
self.attachments.push(item);
console.log(self.attachments()); //array
});
})
.fail(function( jqxhr, textStatus, error ) {
var err = textStatus + ", " + error;
console.log( "Request Failed: " + err );
});
refresh()函数:
self.refresh = function() {
self.getAttachments();
//self.attachments(self.getAttachments());
//ko.mapping.fromJS(self.getAttachments(), self.attachments);
console.log("attachments:" + self.attachments());
}