[英]ember.js access sibling hierachy functions
js. js。
Right Now: I have a graphView containing 3 tabs A, B, and C. For each tab A, B or C, each has a view and a coffee.js. 现在:我有一个graphView包含3个选项卡A,B和C。对于每个选项卡A,B或C,每个都有一个视图和coffee.js。 In each view, there's a button and in each corresponding coffee.js, each contains a triggerSelf function.
在每个视图中,都有一个按钮,并且在每个对应的coffee.js中,每个都包含一个triggerSelf函数。
As following: 如下:
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
What I want to achieve: 我要实现的目标:
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
Could anyone help please? 有人可以帮忙吗?
Thank you. 谢谢。
I would do it through the controller which (presumably) they all share. 我会通过(大概)它们都共享的控制器来实现。
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();
});
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.