次のコントローラーは、選択が変更された場合にテーブルを更新します。それはうまくいきます。しかし、戻るボタンは、最後の選択ではなく、最後のルートに戻ります (これは、この場合予想される動作です)。
しかし、戻るボタンで最後の選択に戻ることをお勧めします。これまでのところ、新しいルートを作成し、selectionChanged から transitionTo を呼び出し、this.selection.name を新しいルートとして設定しようとしました。しかし、それは機能しませんでした (未定義のメソッド「transitionTo」を呼び出すことはできません)。
質問は次のとおりです。ブラウザの場所で選択の変更を反映するための推奨される方法は何ですか?
NewApp.GridController = Em.Controller.extend({
content: [], // bound to Ember.Select view
selection: null, // bound to Ember.Select view
tableContent: [],
selectionChanged: function () {
var that = this;
if (this.selection) {
$.getJSON("api/v1/lists/" + this.selection.name + "/prices", function (content) {
that.set('tableContent', content);
NewApp.router.root.prototype.switchRoute();
});
}
}.observes('selection'),
initController: function () {
var that = this;
$.getJSON("api/v1/lists/all", function (content) {
that.set('content', content);
that.set('selection', content.get(0));
});
}
});
ルータは次のようになります。
NewApp.Router = Ember.Router.extend({
enableLogging: true,
location: 'hash',
root: Em.Route.extend({
show3: Ember.Route.transitionTo('root.third'),
switchRoute: Ember.Route.transitionTo('root.listname'),
index: Em.Route.extend({
route: '/',
redirectsTo: 'main'
}),
main: Em.Route.extend({
route: 'app',
connectOutlets: function (router, context) {
router.get('helloController').initController();
return router.get('applicationController').connectOutlet({
name: 'hello'
});
}
}),
third: Em.Route.extend({
route: 'third',
connectOutlets: function (router, context) {
router.get('gridController').initController();
return router.get('applicationController').connectOutlet({
name: 'grid'
});
}
}),
listname: Em.Route.extend({
route: 'routeName' // static, just for testing
})
})
});