问题描述
使用最新的 Ember,以下简单的 ContainerView 会导致错误:
With latest Ember, the following simple ContainerView causes the error:
弃用:不再支持使用 defaultContainer.[defaultContainer#lookup] 见:http://git.io/EKPpnA
DEPRECATION: Using the defaultContainer is no longer supported. [defaultContainer#lookup] see: http://git.io/EKPpnA
我想这与我将视图附加到控制器中的方式有某种关系,
I guess this is somehow related to the way I append the view into the controller,
请注意,如果子视图中的模板是内联编译的,则不会发生错误,只会在向视图的模板"属性提供外部模板时发生.
Please note that if template in the sub views are compiled inline the error doesn't happen, it only happens when providing external template to the 'template' property of the view.
http://jsbin/uqawux/2/edit
谢谢
推荐答案
该弃用消息引用此 gist,如果您查看迁移路径:(WIP) 部分,它包含以下文本:
That deprecation message reference this gist, if you look the migration paths: (WIP) section, it have the following text:
如果您在 parentView 的上下文之外创建视图(这可能不推荐,但它正在发生)你会想要确保通过容器本身实例化您的视图.
if you are creating views outside the context of a parentView (this may not be recommended, but it is happening) you will want to make sure to instantiate your view via the container itself.
this.container.lookup('view:apple')
// will provide a instance of apple view.
因此您需要更新代码以使用容器而不是 App.FooView.create()
.
So you need to update your code to use the container instead of App.FooView.create()
.
App.IndexController = Ember.Controller.extend({
show: function() {
var v = this.container.lookup('view:foo');
v.appendTo(App.rootElement);
}
});
根据您的版本,您将收到一条新的警告消息:
Depending of your version, you will receive a new warning message:
弃用:直接在控制器上实现的动作处理程序是不推荐使用 actions
对象上的动作处理程序(显示在)
DEPRECATION: Action handlers implemented directly on controllers are deprecated in favor of action handlers on an
actions
object (show on )
在这种情况下,将您的操作放在 actions
对象中:
In that case put your action in a actions
object:
App.IndexController = Ember.Controller.extend({
actions: {
show: function() {
var v = this.container.lookup('view:foo');
v.appendTo(App.rootElement);
}
}
});
这是使用最新 ember 版本更新的 jsbin,没有警告http://jsbin/uqawux/4/编辑
This is a updated jsbin using the lastest ember version without warnings http://jsbin/uqawux/4/edit
这篇关于Simple ContainerView 导致“不再支持使用 defaultContainer".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论