简体   繁体   English

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

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

So i've got this in my 所以我已经有了这个

Application Route 申请途径

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);
    }
});

Application Controller 应用控制器

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

Then I have this in my template 然后我的模板中有这个

    <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}}

But nothing appears in the select box. 但是在选择框中什么也没有出现。 I've also tried just looping through the property like so 我也尝试过像这样遍历属性

{{#each all_departments}} {{department_name}} {{/each}} doesn't show anything either. {{#each all_departments}} {{department_name}} {{/each}}也不显示任何内容。

Your model alias all_projects and all_departments will be an array object. 您的模型别名all_projects和all_departments将是一个数组对象。 So your should extend ArrayController for your ApplicationController instead of extending ObjectController. 因此,您应该为ApplicationController扩展ArrayController而不是扩展ObjectController。

Hope that will solve the issue of loading the Ember.Select view. 希望能解决加载Ember.Select视图的问题。

Given below an basic example of multiple model with Ember.Select view to render the two models. 下面给出了使用Ember.Select视图的多个模型的基本示例,以呈现两个模型。

JSBIN Ling 吉斌玲

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

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