0
在動態細分模板中,如何使用路線顯示模型中的數據?Ember:如何訪問動態細分模板中的其他模型數據
所以,比如我有這三個途徑與phone_id
動態段
Router.map(function() {
this.route('phones');
this.route('phone', {path: 'phones/:phone_id'});
this.route('numbers');
});
在phones/:phone_id
模板,我試圖顯示所有的數字模型。所以在phone.js
路線中,我試圖返回數字模型並輸出它,但它什麼都沒顯示。
import Ember from 'ember';
export default Ember.Route.extend({
numbers(){
return this.get("store").findAll('number')
}
});
我試過它也與params.phone_id
作爲參數,但它沒有奏效。 (也沒有錯誤顯示)。
模板phone.hbs
看起來像
<h5> Device Id: {{model.device_id}}</h5>
{{#each numbers as |number|}}
{{number.digits}}
{{/each}}
有趣的是model.device_id
返回即使我甚至沒有將其設置爲返回,在phone.js
路線正確的。但是我爲其實現的numbers
的每個循環都不返回任何內容。
是否有解決方法來返回phone.hbs
動態片段模板中的數字模型數據?
編輯:
我達到我的動態段的方式是通過一個鏈接:
{{#each phones as |phone|}}
<li>{{#link-to 'phone' phone}} {{phone.id}}{{/link-to}}</li>
{{/each}}
這些不能在'phone.hbs'模板中使用,但可以在其他模板中使用。看起來像模型被覆蓋,因爲它是一個動態的細分市場 –
告訴我一件事是你通過linkTo這個動態的細分市場路線?如果您使用linkto並將phoneModel作爲id參數傳入,那麼將跳過模型鉤子,並將控制器模型設置爲您從linkTo傳遞的模型。 –
是的,我是,請看看我的編輯,讓我知道我可以通過id,而不是模型參數,因爲你提到。 –