从另一个视图访问Ember ApplicationController

Mis*_*sha 11 ember.js

我想初始化ApplicationController中所有用户的列表,然后在另一个视图的下拉列表中显示它们.如何从不同的视图访问ApplicationController?

这是相关代码:

  App.ApplicationRoute = Ember.Route.extend({
   setupController:function(controller) {
    controller.set('users', App.User.find());
    controller.set('selectedUser', null);
  }
 });

 <script type="text/x-handlebars" data-template-name="users">
   {{view Ember.Select
   contentBinding="App.ApplicationController.users"
   optionValuePath="content.id"
   optionLabelPath="content.fullName"
   selectionBinding="App.ApplicationControllerselectedUser"}}

   selected user: {{App.ApplicationController.selectedUser.fullName}}
 </script>
Run Code Online (Sandbox Code Playgroud)

Tho*_*mas 19

needs在视图的控制器中指定

App.UsersController = Ember.Controller.extend({
  needs: ['application']
});
Run Code Online (Sandbox Code Playgroud)

在您的视图中,您可以按如下方式访问应用程序控制器

controllers.application
Run Code Online (Sandbox Code Playgroud)

在你的例子中

<script type="text/x-handlebars" data-template-name="users">
  {{view Ember.Select
         contentBinding="controllers.application.users"
         optionValuePath="content.id"
         optionLabelPath="content.fullName"
         selectionBinding="controllers.application.selectedUser"}}

  selected user: {{controllers.application.selectedUser.fullName}}
</script>
Run Code Online (Sandbox Code Playgroud)