未捕获错误:断言失败:尝试注册已使用的ID的视图:名称

时间:2014-11-19 23:52:07

标签: javascript ember.js ember-cli

我使用ember-cli随机开始在我的应用上收到此错误Uncaught Error: Assertion Failed: Attempted to register a view with an id already in use: name。 我只有两条路线

Router.map(function() {
  this.route('buy');
  this.route('rent');
});

没有控制器,我的索引路由会将我重定向到buy

redirect: function() {
  this.transitionTo('buy');
}

我的rent路由也会呈现buy模板

renderTemplate: function() {
  this.render('buy');
}

我没有rentindex模板。 我不知道这个错误来自哪里。

2 个答案:

答案 0 :(得分:9)

我弄明白为什么,原来我的模板上有两个具有相同ID的输入, {{ input name="name" id="name" placeholder="Full Name" class="full-width" }}两次在不同的地方。如果错误消息可以提供更多信息,并为您提供实际代码的一行,而不是仅显示throw new EmberError("Assertion Failed: " + desc);文件中的vendor.js行,那将非常有用。

答案 1 :(得分:3)

我遇到了同样的问题,最后我只是在Chrome Elements标签中搜索了所有已识别为重复的ID的元素。事实证明这是查找重复ID来源的好方法。