渲染多个EmberJS视图时断言失败 [英] Assertion Fails while Rendering Multiple EmberJS Views

查看:182
本文介绍了渲染多个EmberJS视图时断言失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用视图帮助器多次,以便渲染相同的模板,但每次都使用不同的参数,主要是布尔作为选项标志。



但是,每当我渲染超过1个相同的视图时,我会收到以下错误:



断言失败:尝试注册已使用ID的视图:null



我的元素标签没有ember id,例如 id =ember224



我在JSBin中复制了这个问题:


请注意,在JSBin中,您无法看到控制台中记录的错误,
无论什么原因。一个简单的复制并粘贴到
http://www.embersandbox.com/ ,你可以打开控制台并查看
的错误本身。


http://jsbin.com/UHOh/1/edit?html,js,output


$有没有人知道为什么会发生这种情况?如果是这样,这可能是一个问题吗?所有其他的工作,因为它现在应该,所以我倾向忽略它。



谢谢!

解决方案

您正在覆盖Ember.View的init()方法,而不是调用this._super()。这导致视图不能正确初始化,导致您的视图元素缺少id属性(例如id =ember224)。



以下是与原始JSBin的链接,添加MyCustomView.init()调用this._super()。你会发现view元素现在有id属性。



http://jsbin.com/UHOh/11/edit?html,js,output


I am using the view helper multiple times, in order to render the same template but with different parameters every time, mostly booleans acting as option flags.

However, I get the following error, whenever I render more than 1 of the same view:

Assertion failed: Attempted to register a view with an id already in use: null

My element tags do not have an "ember id", e.g. id="ember224".

I replicated the issue in a JSBin:

Please note that in JSBin you won't be able to see the error logged in the console, for whatever reason. A simple copy and paste over to http://www.embersandbox.com/ and you can open up the console and see the error itself.

http://jsbin.com/UHOh/1/edit?html,js,output

Does anyone have any idea why this happens? If so, could it be a problem? Everything else is working as it should, for now, so I am inclined to ignore it.

Thanks!

解决方案

You are overriding the init() method of Ember.View and not calling this._super(). This causes the view to not initialize properly resulting in your view elements missing id attributes (e.g. id="ember224").

Below is a link to your original JSBin with the addition of MyCustomView.init() calling this._super(). You will find the view elements now have id attributes.

http://jsbin.com/UHOh/11/edit?html,js,output

这篇关于渲染多个EmberJS视图时断言失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆