0

ルートからダイナミックセグメントにアクセスすると、奇妙な動作が発生します。

キーワードモデルがあります。キーワードのコレクションを表示するとき、パスを読み取ってほしい/keywords。単一のキーワードにアクセスするとき、パスにを読み取らせたい/keyword/:KEYWORD_ID。慣例により、Emberはあなたに次のことをしてほしいと思っています…</ p>

this.resource('keywords', { path: '/keywords' }, function() {

    this.route('new', { path: '/new' });
    this.resource('keyword', { path: '/keyword/:keyword_id' }, function() {

        this.route('edit');

    });

});

上記の動作を実現するために、私は次のことを行っています...

this.resource('keywords', { path: '/keywords' }, function() {

    this.route('new', { path: '/new' });

});

this.resource('keyword', { path: '/keyword/:keyword_id' }, function() {

    this.route('edit');

});

ただし、2番目のアプローチであるKeywordIndexのルート(つまり、単一のキーワードオブジェクト)を使用する場合、paramsオブジェクトはnullであり、画面上のコンテンツは空白です。

App.KeywordIndexRoute = Ember.Route.extend({

    model: function(params) {

            return App.Keyword.find(params.keyword_id);

    },

    renderTemplate: function(controller, model) {

        this.render({outlet: 'page'});

    }

});

誰かがこの問題を経験しましたか?この問題に取り組むためのより良い方法はありますか?

4

1 に答える 1

0

問題が解決しました。問題は、この特定のオブジェクトのAPIにありました。このルーティングパターンを検討している人にとっての最良のアプローチは次のとおりです...

this.resource('keywords', { path: '/keywords' }, function() {

    this.route('new', { path: '/new' });

});

this.resource('keyword', { path: '/keyword/:keyword_id' }, function() {

    this.route('edit');

});

次に、このようにコントローラーのモデルにアクセスします...

App.KeywordIndexRoute = Ember.Route.extend({

    model: function(params) {

        return this.modelFor("keyword");

    },

    renderTemplate: function(controller, model) {

        this.render({outlet: 'page'});

    }

});
于 2013-03-15T15:41:55.577 に答える