问题
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