Ember CLI Mirage:如何过滤掉 return 值?

Ember CLI Mirage: How to filter out return value?

这就是我获取 config.js 中所有数据的方式:

this.get('/rentals', function (schema, request) {
    if (request.queryParams.value) {
        // The code should be here...
    } else {
        return schema.rentals.all();
    }

}

我查看了文档,但无法获得过滤后的文档。明明有all()find()findBy()create()等命令,但是没有过滤掉returns。有帮助吗?

发现:filter 可以与 all() 一起使用。

this.get('/rentals', function (schema, request) {
    if (request.queryParams.value) {
        let filteredRentals = schema.rentals.all().filter(function (i) {
            return i.attrs.value.toLowerCase().indexOf(request.queryParams.value.toLowerCase()) !== -1;
        });
        return filteredRentals;
    }
    return schema.rentals.all();
});