0
我的角色資源上有一個嵌套的資產資源。我已經讀過所有這些,我應該可以使用this.modelFor
來獲取關聯的父模型,但是當我使用它時,我的結果是未定義的。我哪裏錯了?Ember.js中的另一個動態段問題
型號/ character.js
export default DS.Model.extend({
assets: DS.hasMany('asset', { async: true }),
...
});
型號/ asset.js
export default DS.Model.extend({
character: DS.belongsTo('character', { async: true }),
...
});
router.js
Router.map(function() {
this.resource('characters', function() {
this.route('show', { path: '/:character_id'} , function() {
this.resource('assets', function() {
});
});
});
...
});
路線/字符/ show.js
export default Ember.Route.extend({
model: function(params) {
return this.store.find('character', params.character_id);
}
});
路由/資產/ index.js
export default Ember.Route.extend({
model: function() {
return this.modelFor('character').get('assets');
}
});
模板/字符/ show.hbs
<div class="row">
<h2>{{name}}</h2>
{{#link-to 'assets' this}}Assets{{/link-to}}
</div>
作爲this.modelFor( '字符')返回未定義:
Error while processing route: assets.index Cannot read property 'get' of undefined TypeError: Cannot read property 'get' of undefined
我的路線看起來和我想象的一樣,讓我產生了/ chararcters /:charater_id:/ assets route: