0

我试图在另一个路由器中渲染的来自路由器的数据没有加载,因为主路由器的数据被加载。当我直接进入我试图渲染的路线时,数据就会被加载。

可以找到调试这种情况的方法,感谢您的建议,伙计们!

PS我通过调用渲染函数进行渲染

为了澄清这个问题:

我有 2 条路线

EmberTester.UsersRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('user');
  },
  isEditing: false,
  actions: {
    select: function(post) {
      this.render("external_users", {
        into: "users",
        outlet: "externalOutlet"
      });
      return false;
    }
  }
});

EmberTester.ExternalUsersRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('external_user');
  }
});

当我在其中调用一个render函数时selectUsers Route它会呈现模板,但没有我在 中定义的模型ExternalUsersRoute,并且我的模板要求正确呈现数据。

有没有办法让一个钩子为另一个路由器加载数据?

更新

这是我的路由器配置:

EmberTester.Router.map(function() {
  this.resource("users");
  return this.resource("external_users");
});

EmberTester.UsersRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('user');
  },
  actions: {
    select: function(post) {
      this.set('controller.content', this.store.find('external_user'));
      this.render("external_users", {
        into: "users",
        outlet: "externalOutlet"
      });
      return false;
    }
  }
});

EmberTester.ExternalUsersRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('external_user');
  }
});

EmberTester.externalUsersController = Ember.ObjectController.extend({
  needs: "users",
  userNameBinding: Ember.Binding.oneWay('controllers.users.external_user_id')
});

EmberTester.UsersController = Ember.ObjectController.extend({
  needs: ["external_users"],
  external_user_id: null
});

这是我的看法users

%h1 Feeds
.col-md-8
  .input-group
    %span.input-group-addon @
    {{view Ember.TextField valueBinding="external_user_id" classNames="form-control" action="select" placeholder="feedname"}}
{{outlet externalOutlet}}        
%br
.col-md-8
  .panel.panel-default
    .panel-heading header here
    .panel-body to be used as description
    %table.table.table-striped
      %tr
        %th ID
        %th Name
      = hb "each user in content" do
        %tr
          %td
            = hb 'user.id'
          %td
            = hb 'user.first_name'
            = hb 'user.last_name'               

这是我对External Users[我不确定我的 _external_users_ 是否应该包含在内容中,但在渲染时没有对服务器的请求]的看法

.col-md-8 
  .panel.panel-default
    .panel-heading
      .glyphicon.glyphicon-picture External users    
    .panel-body
      .input-group
        %span.input-group-addon @
        {{view Ember.TextField valueBinding="userName" classNames="form-control" action="select" placeholder="feedname"}}
      = hb "each external_user in content" do
        = hb 'external_user.username'
4

0 回答 0