2012-12-11 26 views
1

我有一個應用程序,其中一個ContainerView有超過6個動態childViews。我發現Ember沒有連接到各自的childViews的控制器,我的數據與這個childViews目前正在retreiving在childViews本身。我試過甚至使用containerView的控制器,但是childView的數據彼此獨立並且需要多個請求來獲取數據。有沒有更好的辦法可以做到這一點?下面是示例代碼,我做了RightNow如何從不同的AJAX請求containerView的childViews的數據?

var App=Ember.Application.create(); 
App.TestView=Ember.ContainerView.create({ 

    init: function(){ 
    var childViews=this.get('childViews'); 
    childViews.pushObject(Ember.View.create({ 
     data:this.getData(), 
     getData : function() { 
     //Ajax Call 

     } 

    })); 

    } 

}); 

App.TestController=Ember.Controller.create({ 
    content : [] 
}); 
+0

我並不真正需要'燼,data'我的應用程序主要是分析一種.. – thecodejack

回答

1

也許你可以獲取容器視圖的控制器的數據,和他們分享通過計算性能的子視圖。喜歡的東西:

App.TestController = Ember.Controller.extend({ 

    dataForChild1: function() { 
    return $.getJSon().data; // make here the ajax call you need 
    }.property() 

    ... 
}); 

App.TestView = Ember.ContainerView.extend({ 

    childViews: ['view1', 'view2'], 

    view1: Ember.View.extend({ 
    dataBinding: 'controller.dataForChild1' 
    }) 
}); 
+0

啊考慮這一選項,但這個問題是,'childviews'是動態... – thecodejack

+0

動態的意義你不知道他們的數量? –

+0

是......數可能更多... – thecodejack