ember.js - Navigating to Record works, but deep link throws error? -
i have simple emberjs application 2 simple models (ember-model). accounts , items, while account hasmany items.
so when navigate #/accounts/1/items links in application works fine. when directly reload #/accounts/1/items error:
assertion failed: value #each loops on must array. passed <app.account:ember335> (wrapped in (generated items controller)) ember.js?body=1:382 uncaught typeerror: object [object object] has no method 'addarrayobserver' ember.js?body=1:19476 assertion failed: emptying view in inbuffer state not allowed , should not happen under normal circumstances. there bug in application. may due excessive property change notifications. ember.js?body=1:382
this how app looks like:
app.router.map ()-> @resource 'accounts', -> @resource 'account', path: ':account_id', -> @resource 'items' app.accountroute = ember.route.extend model: (params) -> app.account.find(params.account_id) app.itemsroute = ember.route.extend model: -> @.modelfor('account').get('items') app.account = ember.model.extend name: ember.attr('string') item_ids: ember.attr(), items: (-> app.items.find(@.get('comment_ids')) ).property('comment_ids') app.item = ember.model.extend name: ember.attr('string')
controllers standard (empty).
in js console call works fine , returns correct results, after error thrown (and nothing rendered):
app.account.find(1).get('items')
i have no idea why happening , code seems straight forward annoying not have clue. has idea?
i no ember-data expert, seems returning promise. therefore should try:
app.itemsroute = ember.route.extend({ model : function(){ var accountpromise = app.account.find(1); var itemspromise = ember.deferred.create(); accountpromise.then(function(account){ itemspromise.resolve(account.get("items")); }); return itemspromise; } });
why have way?
app.account.find(1);
performs asynchronous call , therefore returns promise.- that's why can't return items, have wait accountpromise fulfilled.
- you return new promise (
itemspromise
) gets fulfilled when accountpromise gets fulfilled. - because return promise, ember waits fulfilled , uses result model controller.
ps: seems little bit complicated me. thinks work, there might more elegant solution.
Comments
Post a Comment