Answer the question
In order to leave comments, you need to log in
How to access the model after it is filled with the fetch method?
I create a model, fill it with the data of an authorized user.
Now I want to use this data, but I can only see it in: this.model.fetch({ success: this.render });
namely, in the success function , here it successfully displays everything.
If I try to display the model outside of it, I get: undefined
How can I pull data from this model? I need to pass the user id to another model to display records.
App.Models.AuthedUser = Backbone.Model.extend({
url: '/authed_user'
});
App.Views.AuthedUser = Backbone.View.extend({
initialize: function () {
_.bindAll(this, "render");
this.model.fetch({ success: this.render });
},
render: function () {
App.Models.user = this.model.toJSON();
console.log(App.Models.user);
}
});
var authedUserFoo = function () {
var authedUser = new App.Models.AuthedUser();
var authedUserView = new App.Views.AuthedUser({ model: authedUser });
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question