1

I am new to backbone.js and I'm stuck with a simple task.
I want to fetch a record from a Database and put it into a model. The fetching seems to work, but I can't get the model attributes. Here my code:

My Model:

window.Model = Backbone.Model.extend({

url: "mobile-rest/get-anzeige",

initialize:function () {

  },
});

My View:

window.Page = Backbone.View.extend({

initialize:function () {
    this.template = _.template(tpl.get('page'));
},

render:function (eventName) {
    var self = this;
    this.getRecord(function(resp){
        $(self.el).append(self.template({model: self.model}));
        console.log(self.model);       //works and I see the right values in the console
        console.log(self.model.title);  //is undefined
        console.log(self.model.get('title');  //also undefined 
    });


    return this;
},

getRecord: function(callback){
    this.model= new Model({id: this.id});
    this.model.fetch({data: $.param({id: this.id}), success: callback()});
}


});

So the fetching seems to work, but how can I access the attributes?

4

1 に答える 1

0

「callback()」を「callback」に変更することで、今すぐ機能させることができました

于 2012-10-21T20:30:43.497 に答える