有没有办法让 Ember 中的嵌套 url 发出单个请求而不是多个请求?
我的网址看起来像这样
/clients/:client_id/claims/:claims_id/lines/:line_id
路由也嵌套在 ember 路由器中以进行匹配。
当我可能只需要 1 个时,我想做的不是提出 6 个请求
而且当我手动更改 url 中的 :line_id 时,它不会使用新记录更新 DOM。不应该吗?
路由器
Nucleus.Router.map(function () {
this.resource("clients", { path: 'clients' }, function () {
this.resource("client", { path: ':client_id' }, function () {
this.resource("claims", function () {
this.resource('claim', { path: '/:claim_id/:claim_sub' }, function () {
this.resource('lines', function () {
this.resource('line', { path: ':line_id' }, function () {
this.resource('flags', function () {
this.resource('flag', { path: ':flag_id' });
});
});
});
});
});
});
});
this.route("errors", { path: '/errors/:error_id' });
});
我的路线看起来像这样
Nucleus.ClientsRoute = Nucleus.Route.extend({
model: function (params) {
return Nucleus.Client.find('clients');
}
});
Nucleus.ClientRoute = Nucleus.Route.extend({
model: function (params) {
return Nucleus.Client.find('client', params);
}
});
Nucleus.ClaimsRoute = Nucleus.Route.extend({
model: function (params) {
var client = this.modelFor('client'),
clientId = client.get('data.id');
params.client_id = clientId;
return Nucleus.Claim.find('claims', params);
},
goToNextClaim: function (claim) {
this.transitionTo('claim', claim);
}
});
Nucleus.ClaimRoute = Nucleus.Route.extend({
model: function (params) {
var client = this.modelFor('client'),
clientId = client.get('data.id');
params.client_id = clientId;
return Nucleus.Claim.find('claim', params);
}
});
Nucleus.ApplicationRoute = Ember.Route.extend({
setupController: function () {
this.controllerFor('meta_property').set('model', Nucleus.MetaProperty.find('meta_property'));
this.controllerFor('header').set('model', Nucleus.User.find("user"));
}
});
控制器就是这样
Nucleus.ApplicationController = Nucleus.Controller.extend({
needs: ['meta_property'],
isErrorPage: false,
currentPathDidChange: function () {
if (this.get('currentPath') === 'errors') {
this.set('isErrorPage', true);
} else {
this.set('isErrorPage', false);
}
}.observes('currentPath')
});
Nucleus.ClaimController = Nucleus.ObjectController.extend({});
Nucleus.ClientController = Nucleus.ObjectController.extend({});