1

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 とモデルを使用していません。

4

2 に答える 2

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/を参照してください。

于 2013-02-07T17:20:28.603 に答える
0

ルーターに serialize を実装して、id のデフォルトの動作をオーバーライドします。たとえば、次のようなルートがあります。

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

ルートは次のようになります

Em.Route.extend( {
    serialize: function( model, params ) { 
        return { begin: model.begin.valueOf(), end: model.end.valueOf() };
    }
} );
于 2013-02-20T19:18:17.160 に答える