Ember.js: Design pattern for communicating to view from model -
what's design pattern accessing model's view model?
i have item
ds.model, itemcontroller
, itemscontroller
, , itemview
, linked standard render
in template iterates on itemscontroller's content:
items.hbs:
{{#each item in content}} render 'item' item {{/each}}
i have newitem
event on itemscontroller
, creates new item object , prepends controller's content array:
items_controller:
app.itemscontroller = ember.arraycontroller.extend actions: newitem: -> newitem = @get('store').createrecord 'item' @get('content').insertat(0, item, 0)
this works fine: after next run loop, new itemcontroller + itemview created , changes reflected in dom automatically.
however, want set mouse focus on element inside newly inserted itemview (call function focusme
), seems reduces how can access (or send events to) model's view model? know in general information flows one-way model -> controller -> view in ember, how else accomplish this?
thoughts:
didinsertelement
won't work, because want callfocusme
items created vianewitem
action, , don't want couple every view.- it seems logical place inside
newitem
action definition itself,newitem.getview().focusme()
, of course requires access model's view. - i looked @ get references emberjs views created given model object?, think adding observer every single
itemview
overkill, when newly created items vianewitem
action need focused. - also, tried solution, , couldn't work (that answer on year old).
Comments
Post a Comment