【发布时间】:2014-06-05 07:24:42
【问题描述】:
我正在关注 Ember.js 的视频教程,但有一个模板给我带来了错误。
<script type="text/x-handlebars" id="repositories">
<table class="table table-striped">
{{#each}}<tr><td>{{name}}</td></tr>{{/each}}
</table>
</script>
未捕获的错误:断言失败:变形标记, metamorph-27-start 和 metamorph-27-end,有不同的父母。这 浏览器已修复您的模板以输出有效的 HTML(例如, 检查您是否已正确关闭所有标签并已 用过......')
作为 ember 的新手,我不知道这意味着什么。所以我玩了这个的一些版本,看看有什么用。
错误
{{#each}}<tr><td>test</td></tr>{{/each}}
{{#each}}<tr>test</tr>{{/each}}
{{#each}}<td>test</td>{{/each}}
作品
{{#each}}test{{/each}}
{{#each}}{{name}}{{/each}}
{{#each}}<li>test</li>{{/each}}
{{#each}}<li><span>test</span></li>{{/each}}
<tr>{{#each}}<td>{{name}}</td>{{/each}}</tr>
我从关于 Pluralsight 的精彩培训视频(Rob Conery 的 Ember.js 基础知识)中复制了这一点。它似乎对他有用,要么我复制了错误的东西,要么框架在我运行的更高版本中发生了变化。
希望有人可以在这方面提供帮助。谢谢
更新
我正在运行 ember 的调试版本。断线是
Ember.assert = function(desc, test) {
if (!test) {
throw new Ember.Error("Assertion Failed: " + desc);
}
};
以及测试本身
function _addMetamorphCheck() {
Ember.Handlebars.EachView.reopen({
_checkMetamorph: Ember.on('didInsertElement', function() {
Ember.assert("The metamorph tags, " +
this.morph.start + " and " + this.morph.end +
", have different parents.\nThe browser has fixed your template to output valid HTML (for example, check that you have properly closed all tags and have used a TBODY tag when creating a table with '{{#each}}')",
document.getElementById( this.morph.start ).parentNode ===
document.getElementById( this.morph.end ).parentNode
);
})
});
}
对此的评论继续说:
Ember 构建工具将删除对
Ember.assert()的任何调用 生产版本。
所以这在非调试文件中可能不是问题.. 但它仍然不能说明测试失败,除非测试本身不好?
【问题讨论】:
-
还没有搜索到这个原因,但是如果你将内容包装在
tbodyemberjs.jsbin.com/povovudo/1/edit 中看起来没问题。还有一点就是如果你不放tbody,hbs会为你输入一个,可能和错误有关。 -
@melc 太棒了!无论是 hbs 还是包装 tbody 的浏览器,它都已修复。如果您发布为实际答案,那么我会接受它。谢谢!
-
太好了,刚刚将其发布为答案
标签: html ember.js handlebars.js