2

我想将 CollectionView 插入到视图中。它有效,但显示:

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>

对不起我的英语,我来自俄罗斯,有点懂))

4

1 回答 1

0

IndexView正在直接实例化视图。嵌套视图不推荐使用这种实例化样式,以允许子视图获取其父视图Container

将其更改为myChildView直接声明,弃用警告将消失。

App.IndexView = Em.View.extend({
    myChildView: App.MyCollection
});
于 2013-07-02T08:41:25.703 回答