Reputation: 33
Doing an GET, returning an object. Wondering what the proper way to bind this:
var self = this;
$.getJSON("/api/contentsummary",
function (data) {
self.contentSummary =data.contentSummary;
});
To get this to function properly, I need to bind after every assignment. What's the proper way to do this when the GET function is returning an object?
Upvotes: 2
Views: 188
Reputation: 219920
Use the Knockout mapping plugin:
var self = this;
$.getJSON("/api/contentsummary", function (data) {
self.contentSummary = ko.mapping.fromJS(data.contentSummary);
});
Upvotes: 2