Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you look at how <a href="https://github.com/jashkenas/backbone/blob/1.0.0/backbone.js#L796" rel="nofollow"><code>where</code></a> works:</p> <pre><code>where: function(attrs, first) { if (_.isEmpty(attrs)) return first ? void 0 : []; return this[first ? 'find' : 'filter'](function(model) { for (var key in attrs) { if (attrs[key] !== model.get(key)) return false; } return true; }); } </code></pre> <p>you'll see that it just scanning the models and comparing attributes using <code>!==</code>. When you using <code>!==</code> or <code>===</code> (or <code>!=</code> or <code>==</code> for that matter) to compare arrays, the references are compared, not the content; for example, this is false:</p> <pre><code>[1] === [1] </code></pre> <p>The result is that searching for an array using <a href="http://backbonejs.org/#Collection-where" rel="nofollow"><code>where</code></a> doesn't work that well, <code>where</code> is meant to be a shortcut for searching for simple scalar values.</p> <p>If you need to search for an array, then you can use <a href="http://underscorejs.org/#filter" rel="nofollow"><code>filter</code></a> directly and you can use <a href="http://underscorejs.org/#isEqual" rel="nofollow"><code>_.isEqual</code></a> to help you compare things:</p> <pre><code>var models = coll.filter(function(m) { return _.isEqual(m.get('a'), data); }); </code></pre> <p>If you want one match, use <a href="http://underscorejs.org/#find" rel="nofollow"><code>find</code></a> instead of <code>filter</code>.</p> <p>Demo: <a href="http://jsfiddle.net/ambiguous/PZZv4/1/" rel="nofollow">http://jsfiddle.net/ambiguous/PZZv4/1/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload