Associate controller to a view if the controller exists using emberjs

241 views Asked by At

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

1

There are 1 answers

0
herom On

As mentioned in the comment of your question, the View knows its Controller so I'd go the other way and tell the Controller beforehand which other controllers are needed through its needs property which could then be aliased and observed by the view.