简体   繁体   English

在骨干网集合上的findWhere仅返回一个结果

[英]findWhere on backbone collection only returns one result

I have a backbone collection I am trying to add models to so I can show a list of available forms that you can add to the ui in a drop down. 我有一个中枢集合,我试图向其中添加模型,以便可以显示可添加到ui的可用表单列表。 And this seemed to be working until they needed to be able to add more than one type. 在他们需要能够添加多个类型之前,这似乎一直有效。

It seems though that my findWhere statement when I'm trying to add to the collection is only returning the fist one that has the Show property instead of all of them(There are maybe twenty). 看来,当我尝试添加到集合中时,我的findWhere语句似乎只返回具有Show属性的拳头而不是全部(可能有二十个)。

To add it I am doing something like this. 要添加它,我正在做这样的事情。

this.temp = new Backbone.Collection();
var api = breeze api stuff
this.temp.add(api.collections[(this.templateType)].findWhere({Show : true}))

Is there a way to modify the findWhere so it grabs them all instead of just the first one. 有没有一种方法可以修改find​​Where,这样它就可以全部抓住它们,而不仅仅是第一个。 I was searching, but I can't seem to find anything like this. 我当时在搜索,但似乎找不到类似的内容。 Any help would be appreciated! 任何帮助,将不胜感激!

If you look at the documentation you will notice 如果您查看文档,您会发现

findWherecollection.findWhere(attributes)

Just like where, but directly returns only the first model in the collection that matches the passed attributes. 就像在哪里一样,但是直接返回集合中与传递的属性匹配的第一个模型

Why don't you use where ? 为什么不在where使用?

wherecollection.where(attributes) wherecollection.where(属性)

Return an array of all the models in a collection that match the passed attributes. 返回集合中与传递的属性匹配的所有模型数组 Useful for simple cases of filter 对于简单的过滤器案例很有用

http://backbonejs.org/#Collection-where http://backbonejs.org/#Collection-where

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM