Ember Nested Urls作为单个请求

时间:2013-05-10 20:58:40

标签: ember.js

有没有办法让Ember中的嵌套URL可以针对多个请求发出单个请求?

我的网址看起来像这样

/客户端/:CLIENT_ID /权利要求/:claims_id /行/: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({});

0 个答案:

没有答案