ember.js - How to get the latest active item? -


the following returns active items.

activeitems: ember.computed('items.@each.status', {     get() {         return this.get('items').filter((item) => {             return item.get('status') === 'active';         });     } })  // template {{#each activeitems |activeitems|}}   {{activeitem.status}} {{/each}} 

all of above works. lets want create computed property picks out last activeitem. tried:

activeitem: ember.computed('activeitems', {   get() {     return this.get('activeitems').lastobject;   } }),  // template {{activeitem.status}} <-- returns nothing 

why , how can work?

i see 2 problems:

  1. your computed property has incorrect dependent key. relying on activeitems, problem update when activeitems property returns new object, not when contents updated. should watching activeitems.lastobject.
  2. lastobject computed property, means might not able access without using ember's get() function.

try this:

activeitem: ember.computed('activeitems.lastobject', {     get() {         return this.get('activeitems.lastobject');     } }) 

or, shorthand:

activeitem: ember.computed.reads('activeitems.lastobject') 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -