ルートからダイナミックセグメントにアクセスすると、奇妙な動作が発生します。
キーワードモデルがあります。キーワードのコレクションを表示するとき、パスを読み取ってほしい/keywords
。単一のキーワードにアクセスするとき、パスにを読み取らせたい/keyword/:KEYWORD_ID
。慣例により、Emberはあなたに次のことをしてほしいと思っています…</ p>
this.resource('keywords', { path: '/keywords' }, function() {
this.route('new', { path: '/new' });
this.resource('keyword', { path: '/keyword/:keyword_id' }, function() {
this.route('edit');
});
});
上記の動作を実現するために、私は次のことを行っています...
this.resource('keywords', { path: '/keywords' }, function() {
this.route('new', { path: '/new' });
});
this.resource('keyword', { path: '/keyword/:keyword_id' }, function() {
this.route('edit');
});
ただし、2番目のアプローチであるKeywordIndexのルート(つまり、単一のキーワードオブジェクト)を使用する場合、params
オブジェクトはnullであり、画面上のコンテンツは空白です。
App.KeywordIndexRoute = Ember.Route.extend({
model: function(params) {
return App.Keyword.find(params.keyword_id);
},
renderTemplate: function(controller, model) {
this.render({outlet: 'page'});
}
});
誰かがこの問題を経験しましたか?この問題に取り組むためのより良い方法はありますか?