How to find a model from a collection according to some attribute other than the ID?

后端 未结 4 2179
陌清茗
陌清茗 2020-12-08 00:09

I have a model with several object:

//Model
Friend = Backbone.Model.extend({
    //Create a model to hold friend attribute
    name: null,
}); 

//objects
va         


        
4条回答
  •  抹茶落季
    2020-12-08 00:50

    You can call findWhere() on Backbone collections, that will return exactly the model you are looking for.

    Example:

    var lee = friends.findWhere({ name: 'Lee' });
    

提交回复
热议问题