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

java - HTTP Status 500 - An exception occurred processing JSP page /second.jsp at line 15 -

php - Using str_replace to translate a MySQL Table in html -

asp.net mvc - Cannot display error message on Editor or EditorFor -