3
可能是我最近問過的最直接的問題。Ember.js:從當前活動路線獲取ID
考慮建立像這樣的路線:
Social.Router.map(function() {
this.resource('accounts', function(){
this.resource('account', { path: ':account_id'});
});
});
和URL像這樣:
我該如何獲得ACCOUNT_ID如果我想獲得當前活動的帳戶記錄?最終的目標是,我這樣做:
acct = App.Account.find(12)
當我寧願做這個
acct = App.Account.find(account_id)
更新1
這裏的AccountsRoute:
Social.AccountsRoute = Ember.Route.extend({
model: function() {
return Social.Account.find();
}
});
您是否在問如何檢索當前路徑的動態路徑,或者如何轉換到與給定用戶(即當前用戶)相對應的路徑? – ahmacleod 2013-03-01 19:04:09
你可以添加你的'AccountRoute'類嗎?如果你遵循指導原則,它應該在你的'model'函數中有一個'params'參數,你可以按照[Dynamic Segments guide](http:// emberjs)中的'params.account_id'來檢索它。 – MilkyWayJoe 2013-03-01 19:08:36
在'model'函數中添加'params'參數並嘗試路徑'params.account_id' – MilkyWayJoe 2013-03-01 19:11:51