2
我正在使用試圖使用具有組頭的jQuery模板插件創建模板。 由於是數據驅動,因此在手之前未知組標題。我有模板是:帶組的jQuery模板
<div class='category'>${Category}</div>
<div class='service'><a service_id='${Id}'>${Name}</a></div>
我的數據是:
var movies = [
{ Name: "Meet Joe Black", Category: "First", Id: 1 },
{ Name: "The Mighty", Category: "First", Id: 2 },
{ Name: "City Hunter", Category: "First", Id: 3 },
{ Name: "A movie", Category: "Second", Id: 4 },
{ Name: "Blade Runner", Category: "Third", Id: 5 }
];
我所要的輸出是
<div class='category'>First</div>
<div class='service'><a service_id='1'>Meet Joe Black</a></div>
<div class='service'><a service_id='2'>The Mighty</a></div>
<div class='service'><a service_id='3' >City Hunter</a></div>
<div class='category'>Second</div>
<div class='service'><a service_id='4'>A movie</a></div>
<div class='category'>Third</div>
<div class='service'><a service_id='5'>Blade Runner</a></div>
我注意到知道如何正確設置模板爲了達成這個。