user1959772
user1959772

Reputation: 33

Knockout Object Binding

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

Answers (1)

Joseph Silber
Joseph Silber

Reputation: 219920

Use the Knockout mapping plugin:

var self = this;

$.getJSON("/api/contentsummary", function (data) {
    self.contentSummary = ko.mapping.fromJS(data.contentSummary);
});

Upvotes: 2

Related Questions