Search code examples
derbyjs

DerbyJS get model as array


I want to be able to get a collection as an array so that I can in the template use {{each}} on it.

It is a collection of users, which are objects, {{each}} doesn't work with objects


Solution

  • Specifically, you can call model.filter() with null for the function, and it will create a list out of all items in the input object. This can be handy as a way to render all subscribed items in a collection, since only arrays can be used as an input to {{each}} template tags.

     var filter = model.filter( model.scope('pants'), null);
     filter.ref('_page.pantsArray');
    

    Here is a link to more details on how to use filters in the derby documentation: http://derbyjs.com/docs/derby-0.6/models/filters-and-sorts