2013-02-07 54 views
1

我有得到linkTo車把助手問題工作使用灰燼PRE4 linkTo車把

我有這條路線設置:

this.resource("contact", function(){ 
     this.route('new'); 
     this.route('show', { path: "/:contactid" }); 
     this.route('edit', { path: "edit/:contactid" }); 
    } 
在我的模板

我有以下代碼:

{{#each entry in controller.entries}} 
{#linkTo "contact.show" entry href="true" }}test {{firstname}} {{lastname}}{{/linkTo}} 
{{/each}} 

生成的鏈接,雖然是/聯繫人/顯示/未定義

我在做什麼錯?

旁註:我沒有使用Ember.Data和模型。

回答

1

灰燼預計參數按照慣例modelname_id,所以路線應改爲:

this.resource("contact", function(){ 
    this.route('new'); 
    this.route('show', { path: "/:contact_id" }); 
    this.route('edit', { path: "edit/:contact_id" }); 
} 

這應該工作,假設entry.get("id")定義。

詳情請參閱http://emberjs.com/guides/routing/specifying-a-routes-model/

+0

的感謝!這也幫助我解決了其他問題 – AyKarsi

0

在路由器中實現序列化以覆蓋id的默認行爲。比如我有一個看起來像路線:

this.route('date', { path: '/:begin/:end'}); 

和路線看起來像

Em.Route.extend({ 
    serialize: function(model, params) { 
     return { begin: model.begin.valueOf(), end: model.end.valueOf() }; 
    } 
});