Reputation: 7953
my backbone model is :
var SampleModel = Backbone.Model.extend({
url : "/trade/investadjustupdate")
});
and i make server call as follows :
var investAdjustModel= new SampleModel();
investAdjustModel.fetch();
when i printed the model like the following : console.log(investAdjustModel);
and this is the screen shot of console.log(investAdjustModel);
i get all the value returned from th server but when i try to get a property like investAdjustModel.get("investAdjustRow"))
it says undefined
so how to get the property which is returned from the server?
Thanks
Upvotes: 3
Views: 89
Reputation: 55750
fetch is Ajax, which is Asynchronous . So it depends where you are trying to log the object.
If you are trying to log it immediately after the fetch then it ought to be undefined.
Either use the success callback
to log it , or listen to a sync
event for the model to log it.
investAdjustModel.fetch({
success: function() {
console.log(investAdjustModel.get("investAdjustRow")));
// This should work
}
});
console.log(investAdjustModel.get("investAdjustRow")));
// Will be undefined here
Upvotes: 2