我想顯示一個項目列表的'顯示'模板。Ember嵌套的路徑show.hbs params不起作用
我index.hbs的工作原理如下:
路線/ index.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return this.store.find('item');
}
});
模板/項目/ index.hbs
items/index.hbs
<ul>
{{#each model as |item|}}
<li>
{{#link-to 'items.show' item}}
{{item.name}}
{{/link-to}}
</li>
{{else}}
<li>No contacts found.</li>
{{/each}}
</ul>
然而,當我點擊一個鏈接,它會將我帶到正確的路線(localhost:4200/items/1),但是,它會給我出現以下錯誤:Error while processing route: items.show Assertion Failed: You may not pass 'undefined' as id to the store's find method Error: Assertion Failed: You may not pass 'undefined' as id to the store's find method
這是我show.js和HBS:
路線/ show.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function(params) {
return this.store.findAll('item', params.id);
}
});
和模板/項目/ show.hbs
{{name}}
這裏是router.js
import Ember from 'ember';
import config from './config/environment';
var Router = Ember.Router.extend({
location: config.locationType
});
export default Router.map(function() {
this.resource('items', function() {
this.route('show', {path: ':item_id'});
});
});
我無法弄清楚它不工作的時候!我讀了參數不是從索引發送到顯示..但然後?!
預先感謝您。任何誇大的答案將非常感激。
請問您的router.js是否使用item_id指定show route?這將有助於如果你顯示你的router.js – xoma
@xoma是的,我添加了上面的參考 –