Backbone collection find I want only one result

2019-09-19 13:51发布

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
        );
    }
);

2条回答
Melony?
2楼-- · 2019-09-19 13:59

You can use findWhere method:

collection.findWhere(attributes) 
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-09-19 14:16

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

查看更多
登录 后发表回答