我有这条路线:
App.Router.map(function() {
// put your routes here
this.resource('about');
this.resource('querydefault');
this.resource('query', {path:':query_done'}, function() {
this.route('time', {path:':time_interval'});
});
});
从此#link-to
过渡{{#link-to 'query.time' this '24' }}Time Interval{{/link-to}}
当我尝试检索query_done时,未定义。
App.QueryTimeRoute = Ember.Route.extend({
model: function (params) {
params.time_interval; (24) OK
params.query_done; UNDEFINED
答案 0 :(得分:0)
Params由处理它们的资源使用。如果您不需要/query
资源,可以执行以下操作:
App.Router.map(function() {
this.resource('about');
this.resource('querydefault');
this.resource('query', {path:''}, function() {
this.route('time', {path:'/query/:query_done/time/:time_interval'});
});
});
但是,我认为真正惯用的解决方案是让资源在其级别上消耗第一个参数,然后将其传递给子资源/路径。
App.Router.map(function() {
this.resource('about');
this.resource('querydefault');
this.resource('query', {path:'/query/:query_done'}, function() {
this.route('time', {path:'/time/:time_interval'});
});
});
App.QueryRoute = Ember.Route.extend({
model: function (params) {
console.log("/Query query_done: " + params.query_done); // OK
return {
queryDone: params.query_done // pass it through here
};
}
});
App.QueryTimeRoute = Ember.Route.extend({
model: function (params) {
console.log("QueryTime query_done: " + params.query_done); // empty
console.log("QueryTime time_interval: " + params.time_interval); // OK
console.log("From parent resource: " + this.modelFor("query").queryDone); // retrieve it through here
return {};
}
});
工作演示here。