My current issue involves fetching a JSON file and storing it in a model for later access. However, I am encountering difficulties when trying to access the attributes through the get()
method as it keeps returning undefined. The JSON file contains an array of games which are objects with various attributes. My main goal is to save them in the model and retrieve them. Here's what I have attempted so far:
var player = Backbone.Model.extend({
initialize: function(app, options) {
this.app = app;
var _this = this;
this.fetch({
url: "someurl",
success: function() {
console.log("success");
}
});
}
});
var instplayer = new player();
instplayer.on('change', function(){
console.log(model);
console.log(model.get(games));
})
I believe that there should be an event trigger to ensure that get()
is called only when the data has fully loaded. Despite my attempts, I still receive undefined. What steps do I need to take to resolve this issue?