title: Sort through a model(array) in Backbone?
body: <p>I'm just learning backbone so forgive me if the title is incorrect.</p>
  
  <p>I want to sort through the model (is the model an array?, have i got that wrong?) but I can't do it. In regular JS I can use this function to sort through an array and I know it works:</p>
  
  <pre><code>getObjects: function(obj, key, val) {
    var objects = [];
    for (var i in obj) {
      if (!obj.hasOwnProperty(i)) continue;
      if (typeof obj[i] == 'object') {
          objects = objects.concat(getObjects(obj[i], key, val));
      } else if (i == key &amp;&amp; obj[key] == val) {
          objects.push(obj);
      }
    }
    return objects;
  }
  </code></pre>
  
  <p>But I don't know where I should put this in Backbone. I tried putting it in the view, but I get an error saying "undefined is not a function" for getObjects.</p>
  
  <pre><code>window.WineListView = Backbone.View.extend({
  
    initialize: function () {
      this.render();
    },
  
    //sort through JSON when getting different priority tasks
    getObjects: function(obj, key, val) {
      var objects = [];
      for (var i in obj) {
        if (!obj.hasOwnProperty(i)) continue;
        if (typeof obj[i] == 'object') {
          objects = objects.concat(getObjects(obj[i], key, val));
        } else if (i == key &amp;&amp; obj[key] == val) {
          objects.push(obj);
        }
      }
      return objects;
    },
  
    render: function () {
      var wines = this.model.models;
      wines = getObjects(wines, 'completed', 'No'); 
      var len = wines.length;
      var startPos = (this.options.page - 1) * 8;
      var endPos = Math.min(startPos + 8, len);
  
      $(this.el).html('&lt;ul class="thumbnails"&gt;&lt;/ul&gt;');
  
      for (var i = startPos; i &lt; endPos; i++) {
        $('.thumbnails', this.el).append(new WineListItemView({model: wines[i]}).render().el);
        //$('.thumbnails', this.el).append('&lt;br/&gt;');
      }
  
      $(this.el).append(new Paginator({model: this.model, page: this.options.page}).render().el);
  
      return this;
    }
  });
  </code></pre>
  
  <p>How can I declare my getObjects function so that it can be accessed? Is the model not an array? Is there a different way I should be sorting? Any help would be greatly appreciated! Thank You.</p>