我多次使用 view
助手,以便每次都使用不同的参数呈现相同的模板,主要是 bool 值作为选项标志。
但是,每当我渲染超过 1 个相同的 view
时,我都会收到以下错误:
断言失败:尝试使用已在使用的 ID 注册 View :null
我的元素标签没有“ember id”,例如id="ember224"
。
我在 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
有人知道为什么会这样吗?如果是这样,这会是一个问题吗?目前,其他一切都在正常工作,所以我倾向于忽略它。
谢谢!
最佳答案
您正在覆盖 Ember.View 的 init() 方法而不是调用 this._super()。这会导致 View 无法正确初始化,导致您的 View 元素缺少 id 属性(例如 id="ember224")。
下面是您的原始 JSBin 的链接,其中添加了调用 this._super() 的 MyCustomView.init()。您会发现 View 元素现在具有 id 属性。
关于javascript - 呈现多个 EmberJS View 时断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18378633/