骨干收集发现我只想要一个结果

Backbone collection find I want only one result

本文关键字:结果 一个 只想 发现      更新时间:2023-09-26

我正在使用find Backbone,我有20-30个结果,我需要第一个结果,但我没有id来过滤id。

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

您可以使用findWhere方法:

collection.findWhere(attributes) 

如果您想获得第一个模型,可以使用collection.at(0)。或者collection.shift(),如果你想获得第一个模型,那么从集合中删除这个模型。在Backbonejs Collection 上阅读更多信息