2013-07-02 46 views
2

我想將CollectionView插入到View中。它的工作原理,但顯示:如何在View中使用CollectionView不使用Ember中的defaultContainer JS

DEPRECATION: Using the defaultContainer is no longer supported. [defaultContainer#lookup] 

如何正確地在視圖中插入的CollectionView?

App = Ember.Application.create(); 

App.Router.map(function() { 
    this.route("index", { path: "/" }); 
}); 

App.FirstView = Em.View.extend({ 
    templateName: 'first' 
}); 

App.SecondView = Em.View.extend({ 
    templateName: 'second' 
}); 

App.MyCollection = Em.CollectionView.extend({ 
    content: ['f','s'], 
    createChildView: function(viewClass, attrs){ 
     if (attrs.content == 'f') { 
      viewClass = App.FirstView ; 
     }; 
     if (attrs.content == 's') { 
      viewClass = App.SecondView ; 
     }; 
     return this._super(viewClass, attrs); 
    } 
}); 

App.IndexView = Em.View.extend({ 
    myChildView: App.MyCollection.create() 
}); 

模板:

<script type="text/x-handlebars"> 
     {{outlet}} 
</script> 
<script type="text/x-handlebars" data-template-name="index"> 
    {{view view.myChildView}} 
</script> 
<script type="text/x-handlebars" data-template-name="first"> 
    search 
</script> 
<script type="text/x-handlebars" data-template-name="second"> 
    client 
</script> 

對不起,我的英語,我是來自俄羅斯和理解它一點點))

回答

0

IndexView直接實例化視圖。這種實例化風格已被嵌套視圖所棄用,以允許子視圖獲得其父母Container

更改爲直接聲明myChildView,棄用警告將消失。

App.IndexView = Em.View.extend({ 
    myChildView: App.MyCollection 
});