Reputation: 15
This refresh when array is changed but;
This is not refresh and not load in init.
json part is here;
$.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
})
})
Thank you all
Upvotes: 0
Views: 719
Reputation: 2258
Take a look here:
your getAttachments() function should just update the contents of the observable array:
ajax call:
$.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() function:
self.refresh = function() {
self.getAttachments();
//self.attachments(self.getAttachments());
//ko.mapping.fromJS(self.getAttachments(), self.attachments);
console.log("attachments:" + self.attachments());
}
Upvotes: 1