1

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

msj121
  • 2,812
  • 3
  • 28
  • 55

2 Answers2

5

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

rkstedman
  • 141
  • 2
  • just to be clear, I need to wrap all of this in model.fetch(model.scope('pants'), function(err){ ...your code...}); or subscribe etc...? – msj121 Jun 03 '15 at 23:03
  • You probably don't want to wrap it in a fetch or subscribe. It sounds like you are using this code in a component controller in order to access it in a view with {{each}}. In this case, I recommend subscribing to the data you need for your component in your route handler rather than fetching it within the controller's init or create methods. – rkstedman Jun 04 '15 at 23:01
1

Use filters top convert a collection to an array (which will also stay reactively up to date).