0
我有我的路由器設置,如:得到的參數值
this.resource('analytics', {path: '/analytics'}, function(){
this.resource('analyticsRuns', {path: ':exerciseRunId/analyticsRuns'},function(){
this.resource('analyticsRun',{path: ':runId'});
});
});
我跳轉到 'analyticsRuns' 路線使用:
this.transitionToRoute('analyticsRuns',{"exerciseRunId":this.get('selectedExerciseRun.id')});
而且我AnalyticsRunsIndexRoute被定義爲:
AS.AnalyticsRunsIndexRoute = Ember.Route.extend({
model : function(params) {
var store = this.get('store');
//console.log(params); //returns empty object
//var exerciseRunId = AS.Analytics.get('exerciseRunId');
exerciseRunId = 577;
if(!(exerciseRunId)){
this.transitionTo('analytics');
}
store.find('analyticsRun',{'exerciseRunId':exerciseRunId});
return store.filter('analyticsRun', function(analyticRun){
return analyticRun.get('exerciseRunId') == exerciseRunId;
});
},
setupController : function(controller,model){
this._super(controller,model);
this.controllerFor('analysisTemplates').set('model',controller.get('store').find('analysisTemplate'));
}
});
我想知道我是否可以訪問AnalyticsRunsIndexRoute中的「:exerciseRunId」值。當我檢查傳遞給這個路由模型的參數參數時,目前沒有設置。然而,刷新時,該參數可用於AnalyticsRunRoute,但僅在刷新時纔可用。那麼我需要使用stateManagement來獲取參數值嗎?或者有更簡單的方法來訪問它。謝謝。
SOLUTION:
再次感謝很多的傑里米通過這個走。這裏是我現在已經成立的東西:
我不顧喜歡路線:
AS.AnalyticsRunsRoute = Ember.Route.extend({
model : function(params) {
return params;
}
});
AS.AnalyticsRunsIndexRoute = Ember.Route.extend({
model : function(params) {
var parentModel = this.modelFor('analyticsRuns');
var exerciseRunId = AS.Analytics.get('exerciseRunId')||parentModel.exerciseRunId;
var store = this.get('store');
if(!(exerciseRunId)){
this.transitionTo('analytics');
}
store.find('analyticsRun',{'exerciseRunId':exerciseRunId});
return store.filter('analyticsRun', function(analyticRun){
return analyticRun.get('exerciseRunId') == exerciseRunId;
});
},
setupController : function(controller,model){
this._super(controller,model);
this.controllerFor('analysisTemplates').set('model',controller.get('store').find('analysisTemplate'));
}
});
嗨傑里米,感謝您的答覆。爲了給你更多關於這個問題的上下文,selectedExerciseRun不是子對象ID,它只是我必須使用的一個過濾標準(在post-> post ember示例中,post_id在這裏不是selectedExerciseRun.Id)。因此,在您建議的更改後,網址看起來像analytics/[object Object]/analytics。 –
看到[更新]我原來的答案。 –
謝謝你在這個傑里米和我一起工作。您提供的更新代碼正是我在「AnalyticsRunsIndexRoute.model」中已經使用的代碼。這是有效的,但是當用戶刷新頁面時,他/她將不得不被重定向到索引頁面,因爲'selectedExerciseRun.id'丟失,這是我希望id成爲URL部分的主要原因,所以即使當用戶刷新頁面我可以向他/她顯示由id過濾的analyticsRuns列表。 –