我有以下模板。我想用中間的逗號來顯示類別。我該怎麼做?帶逗號的jQuery模板格式化
目前,它是在不使用Categories: {{each categories}} <i>${$value}</i> {{/each}}
注意逗號:應該是最後一個項目後面沒有逗號。此外,所有項目應顯示在一行(因爲它是目前)
<script id="Script1" type="text/x-jQuery-tmpl">
<h1>${postTitle}</h1>
<p>
${postEntry}
</p>
{{if categories}}
Categories: {{each categories}} <i>${$value}</i> {{/each}}
{{else}}
Uncategorized
{{/if}}
</script>
<script type="text/javascript">
var blogPostsArray = [
{
postTitle: "Learn jQuery",
postEntry: "Learn jQuery easliy by following.... ",
categories: ["HowTo", "Sinks", "Plumbing"]
},
{
postTitle: "New Tests",
postEntry: "This is a test website"
}
];
$("#blogPostTemplate").tmpl(blogPostsArray).appendTo("#blogPostContainerDiv");
</script>
看到我更新的answser – 2012-02-04 11:26:50