I'd like to know if there is a way to check if a controller exists using Ember, then associate it to a view?
I'm going through a list of element coming from an array, and depending of those element, I generate a view, and sometimes I need to associate a controller to this view. I'm using Ember AppKit.
export default Ember.CollectionView.extend({
init: function () {
this._super();
var self = this;
myList = [{name: 'element-1'}, {name: 'element-2'}];
myList.forEach(function (element) {
self.push(Ember.View.create({
templateName: 'path/to/template/'+element.name,
controller: 'path/to/controller/'+element.name //Associate the controller only if it exists, I don't know how to do that.
}));
});
}
});
Thanks
As mentioned in the comment of your question, the
Viewknows itsControllerso I'd go the other way and tell theControllerbeforehand which other controllers are needed through itsneedsproperty which could then be aliased and observed by the view.