I have a model with several object:
//Model
Friend = Backbone.Model.extend({
//Create a model to hold friend attribute
name: null,
});
//objects
var f1 = new Friend({ name: "Lee" });
var f2 = new Friend({ name: "David"});
var f3 = new Friend({ name: "Lynn"});
and also, I will add these friends object to a collection:
//Collection
Friends = Backbone.Collection.extend({
model: Friend,
});
Friends.add(f1);
Friends.add(f2);
Friends.add(f3);
and now I want to get a model according to the name of the Friend. I know that I can add an ID
attribute to achieve this. But I think there should have some more simple way to do this.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…