ember.js - Resolving promises on filter -


i have filter , can't resolve promise. using model called 'patient' hasmany 'addresses' , want filter out address has addresstype of 'primary'. filter seems working return promise. thank in advance help.

patient controller

app.patientcontroller = ember.objectcontroller.extend    primaryaddress: em.computed 'model.@each.addresses', ->     @get('model.addresses').then (addresses)->       addresses.filterby 'addresstype', 'primary' 

enter image description here

solution (thanks @gjk)

  primaryaddress: em.computed 'model.addresses.@each', ->     @get('model.addresses').filterby('addresstype', 'primary').get('firstobject') 

the obvious issue can see you're not watching @each property of addresses. property depends on model.@each.addresses, means model array, , you're observing addresses property on each item in array. you're not observing content of addresses array, array itself.

it seems me should use model.addresses.@each dependent property. observe addresses on single model, including observing contents of addresses array (which updates when promise resolves).

edit: also, didn't quite read far enough apparently. shouldn't calling then on promise. treat if it's resolved, , it'll updated when resolve. use instead:

app.patientcontroller = ember.objectcontroller.extend   primaryaddress: em.computed 'model.addresses.@each', ->     @get('model.addresses').filterby 'addresstype', 'primary' 

the first time property comptues, promise unresolved filter won't return anything. when promise resolves, property update , filter work expect to.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -