gpt4 book ai didi

ember.js - 从另一个 View 访问 Ember ApplicationController

转载 作者:行者123 更新时间:2023-12-04 01:42:40 24 4
gpt4 key购买 nike

我想初始化 ApplicationController 中所有用户的列表,然后在另一个 View 的下拉列表中显示它们。如何从不同的 View 访问 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>

最佳答案

指定 needs在您的 View Controller 中

App.UsersController = Ember.Controller.extend({
needs: ['application']
});

在您的 View 中,您可以按如下方式访问应用程序 Controller
controllers.application

在你的例子中
<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>

关于ember.js - 从另一个 View 访问 Ember ApplicationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15662407/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com