【问题标题】:Associate controller to a view if the controller exists using emberjs如果控制器存在,则使用 emberjs 将控制器关联到视图
【发布时间】:2014-07-11 13:36:06
【问题描述】:

我想知道是否有办法使用 Ember 检查控制器是否存在,然后将其关联到视图?

我正在浏览来自数组的元素列表,并根据这些元素生成一个视图,有时我需要将控制器与该视图相关联。我正在使用 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.
            }));
        });
    }
});

谢谢

【问题讨论】:

标签: javascript model-view-controller ember.js ember-app-kit


【解决方案1】:

正如您在问题的评论中提到的,View 知道它的Controller,所以我会另辟蹊径,通过它的needs 属性预先告诉Controller 需要哪些其他控制器,然后可以被视图别名和观察。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    相关资源
    最近更新 更多