我正在学习有关jQuery中的模板。并且已经得到了我测试的一些示例代码。但它似乎并不奏效。jQuery模板的问题。对象不支持此方法错误
<html>
<head>
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js " type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.js" type="text/javascript" />
</head>
<body>
<h2>ViewPage1</h2>
<script id="movieTemplate" type="x-jquery-tmpl">
<li><b>${Name}</b> (${ReleaseYear})</li>
</script>
<div id="movieList"></div>
<script type="text/javascript">
var movies = [
{ Name: "The Red Violin", ReleaseYear: "1998" },
{ Name: "Eyes Wide Shut", ReleaseYear: "1999" },
{ Name: "The Inheritance", ReleaseYear: "1976" }
];
// Render the template with the movies data and insert
// the rendered HTML under the "movieList" element
$("#movieTemplate").tmpl(movies).appendTo("#movieList");
</script>
</body>
当调试我可以看到,问题是与.appendTo()方法。而且我也可以在intellisens中看到那种方法不在那里。
我做错了什么?
是什么$( “#movieTemplate”)TMPL(电影)的回报? “tmpl”函数可能无法链接,因此您试图在非jQuery对象上访问jQuery方法。 调试的一个好方法是将链式调用分解为单独的语句。这使得更容易设置断点并查看每个函数的返回值。 – draeton 2011-01-19 21:22:16