mardi 25 juillet 2017

Ember computed property adds comma

I created a computed property to concat two model properties together, and create a list of them. It initially worked like this, which results in a list like so: prop1-prop2, prop1-prop2

modelName: Ember.computed(
  return this.get('modelName').map((o) => {
    return o.get('prop1') + '-' + o.get('prop2');
  }).join(', ');
})

Then I changed it to this which results in the same list:

modelName: Ember.computed(
  this.get('modelName').map((o, i) => {
    return (i > 0 ? ' ' : '') + o.get('prop1') + '-' + o.get('prop2');
  });
})

My question is, where is the second computed property getting the comma to put in the comma-separated list? The initial code I tried was (i > 0 ? ', ' : '') but that was adding two commas. Can anyone explain?




Aucun commentaire:

Enregistrer un commentaire