Ember Controller extend not loading variables into template

♀尐吖头ヾ 提交于 2019-12-13 05:11:34

问题


I've created a mixin, a controller, and a template.

// checkIn/index.js.handlebars
<div class="page-header text-center">
        <h2>
                Check in for
                {{#unless checkInSettings.loaded}}
                        <span class="icon-spinner icon-spin"></span>
                {{else}}
                        <span class="text-info">{{checkInSettings.programName}}</span> - <span class="text-info">{{checkInSettings.programStartDate}}</span>
                {{/unless}}
        </h2>
</div>

// controllers/check_in_controller.js
App.CheckInController = Em.Controller.extend(App.LoadCheckInSettings);

// mixins/load_check_in_settings.js
App.LoadCheckInSettings = Em.Mixin.create({
        init: function() {
                this._super();
                if (!this.get('checkInSettings')) {
                        this.set('checkInSettings', App.CheckInSettings.create());
                        this.get('checkInSettings').set('isLoading', true);
                        var self = this;
                        $.getJSON('/check_in/settings').then(function(data) {
                                self.get('checkInSettings').set('isLoading', false);
                                self.get('checkInSettings').set('programName', data.program_name);
                                self.get('checkInSettings').set('programAcademicYear', data.program_academic_year);
                                self.get('checkInSettings').set('programStartDate', data.program_start_date);
                                self.get('checkInSettings').set('loaded', true);
                        });
                }
        }
});

I am trying to load checkInSettings into the entire CheckInController and all its subcontrollers. I would like to see checkInSettings in my checkIn/index template, but it's not showing up.

What does work is if I create the controller:

// controllers/check_in_index_controller.js
App.CheckInIndexController = Em.Controller.extend(App.LoadCheckInSettings);

However, I want to load the settings for use in other areas of CheckIn, such as the settings page.

Is there a way to load this mixin for the all of CheckIn, in the controller or route, so that I can access checkInSettings from index or settings?


回答1:


Create a controller CheckInsIndexController. On that controller add these two properties needs: ['check_ins'], a checkinsBinding: 'controllers.checkIns.content'. Then you can use checkIns in your index template.



来源:https://stackoverflow.com/questions/19464099/ember-controller-extend-not-loading-variables-into-template

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!