我不確定你的objectToString位於哪裏,但是如果你看到參考here,你會發現他們在.tmpl(method)中添加了必要的幫助函數。
下面是一個例子。我試圖使它類似於你有什麼的問題...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Test jquery Templates</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.4.min.js'></script>
<script type='text/javascript' src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
</head>
<body>
<script id="testTemplate" type="text/x-jquery-tmpl">
{{if title.length}}
<h3>${title}</h3>
<p>Detail: ${$item.objectToString("detail")}</p>
{{/if}}
</script>
<div id="bookList"></div>
<script type='text/javascript'>
$(function(){
var book = [
{ title: "Goodnight, World!",
detail: { author: "Jojo Mojo", synopsis : "What the ..." }},
{ title: "Rainbow",
detail: { author: "Cookie", synopsis : "Huh?" }}
];
$("#testTemplate").tmpl(book, {
objectToString : function(key) {
var detail = this.data[key];
return detail.author + " " + detail.synopsis;
}
}).appendTo("#bookList");
});
</script>
</body>
</html>
你可以看到它here。
這更像我在找的東西。可以發誓我試過了。但是,這看起來很完美 – 2011-01-19 16:49:14