0

我有这个视图,必须添加到body元素中(它不在 a 中ContainerView):

App.NotAForm = Ember.View.extend({
    templateName: 'sample',
    tagName: 'span',
    alert_img: function(event) {
        console.log('event=%o', event);
        event.preventDefault();
        alert(App.myModel.get('myModel_src'));
    },
});

这是原始实现,用于实例化视图:

aView = App.NotAForm.create();
aView.appendTo('body');

但这是抛出:

DEPRECATION: Using the defaultContainer is no longer supported. [defaultContainer#lookup] see: http://git.io/EKPpnA

我已经查看了此处建议的迁移路径,但不知道在这种情况下什么是正确的解决方案。我尝试了以下方法:

aView = App.view.createChildView('App.NotAForm');
aView = App.View.createChildView('App.NotAForm');
aView = Ember.View.createChildView('App.NotAForm');

无济于事。解决此弃用警告的正确方法是什么?

4

1 回答 1

2

目前,您使用此代码手动将视图附加到 DOM:

aView = App.NotAForm.create();
aView.appendTo('body');

而是使用{{view}}帮助器将视图附加到您选择的 Handlebars 模板中:

{{view App.NotAForm}}
于 2013-09-23T13:23:36.267 回答