Rückgrat: Id nicht eingestellt Modell

Habe ich versucht Folgendes ein, um eine id zu meinem Modell:

var globalCounter = 1;

var Model = Backbone.Model.extend({
    initialize: function () {
        this.id = globalCounter;
        globalCounter += 1;
    }
});

myModel = new Model();
console.log(myMode.get('id')); //prints undefined

Wie kann ich eine id zu meinen Modellen?

InformationsquelleAutor Randomblue | 2012-09-24
Schreibe einen Kommentar