【问题标题】:Using Ember Pre4 linkTo handlebar使用 Ember Pre4 链接到车把
【发布时间】:2013-02-07 14:49:33
【问题描述】:

我在让 linkTo Handlebar 助手工作时遇到问题

我有这个路线设置:

   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}}

生成的链接是 /contact/show/undefined

我做错了什么?

旁注:我没有使用 Ember.Data 和模型。

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    Ember 期望参数遵循约定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/

    【讨论】:

      【解决方案2】:

      在路由器中实现序列化以覆盖 id 的默认行为。例如,我有一条看起来像这样的路线:

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

      路线看起来像

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-09
        相关资源
        最近更新 更多