我有一個路由器設置帳戶和帳戶/:account_id選項。當用戶登錄到我的應用程序的索引頁面時,我將它們轉換爲帳戶路線。Ember.js:transitionTo路由,然後到動態段
Social.Router.map(function() {
this.resource('accounts', function(){
this.resource('account', { path: ':account_id'});
});
});
Social.IndexRoute = Ember.Route.extend({
redirect: function() {
this.transitionTo('accounts');
}
});
我想要做的就是根據一些標準將它們轉換到指定的:account_id路由。目前我只想獲得陣列中的第一個帳戶並使用它。但是將來它可能是一種將他們轉換到他們正在查看的最後一個帳戶的方式。事情是這樣的:
Social.IndexRoute = Ember.Route.extend({
redirect: function() {
this.transitionTo('accounts/:account_id');
}
});
的文檔給 「細節」,但沒有提供一個例子,僅提供了以下內容:
transitionTo (name, models)
Transition into another route. Optionally supply a model for the route in question. The model will be serialized into the URL using the serialize hook.
我已經試過如下:
this.transitionTo('accounts/4');
Uncaught Error: assertion failed: The route accounts/4 was not found
this.transitionTo('accounts', Social.Account.find(1));
Uncaught More objects were passed than dynamic segments
你的小提琴似乎沒有工作,所以我用來自CDNjs.com的電話進行了更新:http://jsfiddle.net/XNyme/9/ – commadelimited 2013-02-28 21:31:20