【问题标题】:Ember.js / Handlebars.js error parsing attribute name in handlebars templateEmber.js / Handlebars.js 错误解析车把模板中的属性名称
【发布时间】:2012-09-15 22:49:13
【问题描述】:

我刚刚开始查看 Ember.js,但遇到了包含模板化属性的车把模板的问题:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" />
<script type="text/javascript" src="js/handlebars-1.0.0.beta.6.js" />
<script type="text/javascript" src="js/ember-1.0.pre.js" />
<script type="text/x-handlebars" data-template-name="say-hello">
    <p>First name: {{name.firstName}}</p>
    <p>Last name: {{name.lastName}}</p>
    <p>Last full: {{name.fullName}}</p>

    <a href="#" {{action "edit" on="click"}}>Edit</a>

</script>
</head>
<body>
<h2>Hello World!</h2>
</body>
</html>

我在 Chrome 中遇到错误:

This page contains the following errors:

error on line 14 at column 10: error parsing attribute name
Below is a rendering of the page up to the first error.

我在 Firefox 中也遇到错误。

我猜这是浏览器试图验证文档,有什么办法可以避免这种情况并仍然保留文档类型?

【问题讨论】:

  • 嘿,我也是 ember 新手。我认为这个错误与 doctype 没有任何关系。你在“say-hello”模板中有什么代码?

标签: ember.js handlebars.js


【解决方案1】:

我怀疑 XHTML 文档类型是问题所在。您是否尝试过使用 HTML 5 文档类型 &lt;!DOCTYPE html&gt;

【讨论】:

  • 对不起,堆栈溢出的新手,我已经超出了我的字数限制以寻求回复,请参阅下面的解决方案。
【解决方案2】:

看起来车把模板不是有效的 xhtml。

tomcat 与我的文件一起发送的内容类型是 (application/xhtml+xml)。当您在文档上使用扩展名 .xhtml 时会发生这种情况。

发生这种情况时,文档中的 doctype 是什么无关紧要,文档中会发生 xhtml 验证,并且无法加载。

就我而言,我想我可以预编译把手模板以使其在 xhtml 中工作。

【讨论】:

  • XHTML 是昨天。可能应该考虑在没有它的情况下继续前进。
  • 有时我希望可以,但不幸的是,我想将 ember 嵌入到一些我不想更改文档类型或将所有内容从 xhtml 更改为 html 的旧网站中。
猜你喜欢
  • 1970-01-01
  • 2012-09-07
  • 1970-01-01
  • 2019-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-23
  • 1970-01-01
相关资源
最近更新 更多