渲染多个 EmberJS 视图时断言失败 [英] Assertion Fails while Rendering Multiple EmberJS Views
问题描述
我多次使用 view
助手,以便每次渲染相同的模板但使用不同的参数,主要是布尔值作为选项标志.
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.
但是,每当我渲染超过 1 个相同的 view
时,我都会收到以下错误:
However, I get the following error, whenever I render more than 1 of the same view
:
断言失败:尝试使用已使用的 id 注册视图:null
我的元素标签没有ember id",例如id="ember224"
.
My element tags do not have an "ember id", e.g. id="ember224"
.
我在 JSBin 中复制了这个问题:
I replicated the issue in a JSBin:
请注意,在 JSBin 中,您将无法在控制台中看到错误记录,因为不管什么原因.一个简单的复制和粘贴到http://www.embersandbox.com/ 你可以打开控制台看看错误本身.
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,输出
有谁知道为什么会发生这种情况?如果是这样,会不会有问题?目前,其他一切都在正常工作,所以我倾向于忽略它.
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.
谢谢!
推荐答案
您正在覆盖 Ember.View 的 init() 方法,而不是调用 this._super().这会导致视图无法正确初始化,从而导致您的视图元素缺少 id 属性(例如 id="ember224").
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").
下面是您的原始 JSBin 的链接,并添加了调用 this._super() 的 MyCustomView.init().您会发现视图元素现在具有 id 属性.
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屋!