Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Maybe for this context, you should be creating a view for the collection, not an iteration of views on the member items. In this case, a Handlebar iterator is overkill. In my example below, changes to the firstName or lastName on the Person objects will be bound to the list and update the view.</p> <p>Template:</p> <pre><code>{{App.listController.csv}} </code></pre> <p>Javascript:</p> <pre><code>App = Ember.Application.create(); var Person = Ember.Object.extend({ firstName: null, lastName: null }); var bob = Person.create({ firstName: "bob", lastName: "smith" }); var ann = Person.create({ firstName: "ann", lastName: "doe" }); App.listController = Ember.Object.create({ list: [bob, ann], csv: Ember.computed(function () { var arr = []; this.get('list').forEach(function (item, index, self) { arr.push(item.firstName + ' ' + item.lastName); }) return arr.join(','); }).property('list.@each.firstName', 'list.@each.lastName') }); // any changes to bob or ann will update the view bob.set('firstName', 'tim'); // adding or removing from the array will update the view App.listController.get('list').pushObject(Person.create(firstName: "Jack", lastName:"Dunn"}); </code></pre> <p>Below is my original answer, that didn't work for this context.</p> <p>You should be able to do this with a helper:</p> <pre><code>Handlebars.registerHelper('csv', function(items, options) { var out = ""; for(var i=0, l=items.length; i&lt;l; i++) { out += options.fn(items[i]); if (i &lt; l - 1) { out += ','; } // might want to add a newline char or something } return out; }); // then your template would be {{#csv list}} {{name}} {{status}} {{/each}} </code></pre>
 

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