arrays - In Ember pushObject calls supposed callbacks but removeObject does not -


i got following workspec item controller, controls checkboxes state:

contractorapp.workspeccontroller = em.objectcontroller.extend   needs: ['account']   selected: (->     work_spec = @get 'content'     work_specializations = @get 'controllers.account.work_specializations'     work_specializations.contains work_spec     ).property()    selection_changed: (->     work_spec = @get 'content'     work_specializations = @get 'controllers.account.work_specializations'      limit = @get 'controllers.account.specialization_limit'      if @get( 'selected' ) && work_specializations.get('length') < limit       work_specializations.pushobject work_spec     else       work_specializations.removeobject work_spec     ).observes('selected') 

as see work_specializations parent's set of work specializations: want control (work_specializations.get('length') < limit) addition of element array.

the problem here got observer in model contained work_specializations array:

contractorapp.contractorprofile = ds.model.extend   work_specializations: ds.hasmany "work_specialization"   on_spec_change: ( ->     ws_ids = @get( 'work_specializations').map (ws)->       ws.get 'id'     @set( 'work_specialization_ids', ws_ids )   ).observes 'work_specializations' 

for reason call of 'work_specializations.pushobject work_spec' calls model's callback counterpart removeobject not. ideas why?

you're observing collection itself, not items being added or removed. it's first change triggering observes fire first time.

on_spec_change: ( ->   ws_ids = @get( 'work_specializations').map (ws)->     ws.get 'id'   @set( 'work_specialization_ids', ws_ids ) ).observes 'work_specializations.[]' 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -