我正在尝试使 icanhaz/mustache 循环正常工作,如本答案中所定义,并且在浏览器控制台中出现以下错误:
Uncaught Error: Syntax error, unrecognized expression: <option value="1">First</option>
<option value="2">Second</option>
不知道为什么。我刚刚设法发现这是导致问题的行:
ich.myTemplate(listOfStuff);
这是我的全部代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/tr/html4/transitional.dtd">
<html>
<head>
<title>icanhaz.js demo</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
<script type="text/javascript" src="https://raw.github.com/HenrikJoreteg/ICanHaz.js/master/ICanHaz.js"></script>
</head>
<body>
<select id="mySelectBox">
</select>
<script id="myTemplate" type="text/html">
{{#stuff}}
<option value="{{key}}">{{desc}}</option>
{{/stuff}}
</script>
<script>
$(document).ready( function() {
var listOfStuff = {stuff: [
{key: "1", desc: "First"},
{key: "2", desc: "Second"}
]};
var x = ich.myTemplate(listOfStuff);
$("#mySelectBox").append(x);
});
</script>
</body>
</html>
感谢您的任何建议!