在 ember 中将变量传递给模态

Passing variables to modal in ember

我正在按照 Ember 食谱将路由渲染到模态中:http://emberjs.com/guides/cookbook/user_interface_and_interaction/using_modal_dialogs/。这可行,但我不确定如何将变量传递给我的渲染视图。

具体来说,我想将 'users/filters' 路由加载到模态中,它可以访问 jobTitles 数组。这在我的应用程序路径中简单地定义为 this.store.find('jobTitle')。问题是这似乎无法从 users/filters 控制器或模板访问。 users/filters 路由似乎根本不是 运行 因为我正在使用如下渲染方法:

App.ApplicationRoute = Ember.Route.extend({
  actions: {
    openModal: function(modalName) {
      return this.render(modalName, {
        into: 'application',
        outlet: 'modal'
      });
    }
  }
});

如何将其传递到呈现的模态中?非常感谢。

一种可能是将控制器传递给模态渲染函数:

App.ApplicationRoute = Ember.Route.extend({
    actions: {
        openModal: function(modalName, controller) {
            return this.render(modalName, {
                into: 'application',
                outlet: 'modal',
                controller: controller
            });
        }
    }
});

使用上面的代码调用路由模板中的 openModal 挂钩,并将路由的控制器名称(名称,而不是控制器本身)传递给它。这样您应该能够访问控制器的所有属性。