ember.js访问同级层次结构函数

ember.js access sibling hierachy functions

本文关键字:层次结构 函数 js 访问 ember      更新时间:2023-09-26

js。

现在:我有一个包含3个选项卡a、B和C的graphView。对于每个选项卡A、B或C,每个选项卡都有一个视图和一个coffee.js。在每个视图中,都有一个子按钮,在每个对应的coffee.jsp中,每个都包含一个triggerSelf函数。

如下:

for A: in its view: loadButtonA ; in its aCoffee.js: triggerA function
for B: in its view: loadButtonB ; in its bCoffee.js: triggerB function
for C: in its view: loadButtonC ; in its cCoffee.js: triggerC function

我想要实现的目标:

When I click any button, I want to trigger the other 2 functions in other 2 files.
For example: When I click loadButtonA, I call triggerA, triggerB in bcoffee.js, and triggerC in cCoffee.js

有人能帮忙吗?

谢谢。

我会通过他们共享的控制器来完成这项工作。

App.ViewA = Ember.View.extend({
    actions: {
        triggerA: function () {
            this.trigger();
        }
    },
    trigger: function () {
        /* Handle specific here */
        this.get("controller").send("triggerAny", this);
    }
});
App.GraphController = Ember.Controller.extend({
    graphViews: [], // cache all subview instances here
    actions: {
        triggerAny: function (sender) {
            this.get("graphViews").forEach(function (gv) {
                if (gv === sender) {
                    return;
                }
                gv.trigger();
            });
        }
    }
});