我想将CollectionView插入View。它可以工作,但显示:
DEPRECATION: Using the defaultContainer is no longer supported. [defaultContainer#lookup]
如何在View中正确插入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 :(得分:0)
您的IndexView
直接实例化视图。使用嵌套视图不推荐使用这种实例化方式,以便允许子视图获取其父Container
。
将其更改为直接声明myChildView
,弃用警告将消失。
App.IndexView = Em.View.extend({
myChildView: App.MyCollection
});