2013-02-07 50 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() }; 
    } 
});