chacham15
chacham15

Reputation: 14281

Why isnt the collection being set in Backbone.js?

What is wrong with the following code?


var Item = Backbone.Model.extend({
    defaults: {

    }
});

var List = Backbone.Collection.extend({
    model: Item
});

var collection = new List({'variable':this}); //collection is NOT null!
var result = new Item({'collection':collection}); //result.collection is undefined! why?

Upvotes: 3

Views: 132

Answers (1)

czarchaic
czarchaic

Reputation: 6338

Add your item to the list

var collection=new List,
result=new Item({ name: 'my item'});
collection.add( result );

or

collection.create({ name: 'my item'});

Upvotes: 3

Related Questions