JS。
现在: 我有一个包含3个选项卡A,B和C的graphView。 对于每个选项卡A,B或C,每个选项卡都有一个视图和一个coffee.js。在每个视图中,都有一个按钮,在每个相应的coffee.js中,每个都包含一个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
有人可以帮忙吗?
谢谢。
答案 0 :(得分:0)
我会通过控制器(大概是他们共享的)来做到这一点。
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();
});
}
}
});