Backbone collection find I want only one result

半城伤御伤魂 提交于 2019-12-12 02:40:40

问题


I'm working with find Backbone and I have 20-30 results, I need the first result and I don't have the id for filter for id.

model = coleccion.find(
    function(e){
        return (
           e.get('car').category === data_category &&
           e.get('full_empty') === 0 &&
           e.get('idprovider') === data_provider
        );
    }
);

回答1:


You can use collection.at(0) if you want to get the first model. Or collection.shift() if you want to get the first model, then remove this model from the collection. Read more at Backbonejs Collection




回答2:


You can use findWhere method:

collection.findWhere(attributes) 


来源:https://stackoverflow.com/questions/34288257/backbone-collection-find-i-want-only-one-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!