2014-05-15 1 views
0

js.ember.js 액세스 형제 계층 기능

오른쪽 : 나는 3 개의 탭 A, B 및 C가있는 graphView가 있습니다. 각 탭 A, B 또는 C에 대해 각각보기와 coffee.js가 있습니다. 각보기에는 버튼이 있으며 각 해당 coffee.js에 각각 triggerSelf 함수가 있습니다. 다음으로

:

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 

수있는 사람의 도움을하시기 바랍니다 : 나는 무엇을 달성하고자하는

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 

?

감사합니다.

답변

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(); 
      }); 
     } 
    } 
});