繁体   English   中英

应用程序路径中的多个模型,如何设置控制器Ember.JS

[英]Multiple models in Application route, how to setup the controller Ember.JS

所以我已经有了这个

申请途径

App.ApplicationRoute = App.AuthenticatedRoute.extend({
    model: function() {
        return Ember.RSVP.hash({
            projects: this.store.find('project'),
            departments: this.store.find('department'),
        });
    },
    setupController: function(controller, model) {
        controller.set('model', model);
    }
});

应用控制器

App.ApplicationController = Ember.ObjectController.extend({
    all_projects: Ember.computed.alias('model.projects'),
    all_departments: Ember.computed.alias('model.departments'),
});

然后我的模板中有这个

    <div class="col-xs-1" style="padding:0">
        {{view Ember.Select class="form-control cover-input" content=all_projects value=create_project}}
    </div>
        {{view Ember.Select class="form-control half-input" content=all_departments optionValuePath="content.id" optionLabelPath="content.department_name" value=create_department}}

但是在选择框中什么也没有出现。 我也尝试过像这样遍历属性

{{#each all_departments}} {{department_name}} {{/each}}也不显示任何内容。

您的模型别名all_projects和all_departments将是一个数组对象。 因此,您应该为ApplicationController扩展ArrayController而不是扩展ObjectController。

希望能解决加载Ember.Select视图的问题。

下面给出了使用Ember.Select视图的多个模型的基本示例,以呈现两个模型。

吉斌玲

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM