假設我有一個Customer結構數組,我需要從中生成HTML。以更好的方式從數組中生成html
目前,我做這樣的事情:
jQuery.each(customers, function(index, item) {
html =+ "<tr custID='" + item.ID + "'><td>" + item.Name + "</td><td>" + item.City + "</td></tr>";
});
這裏的問題是,我手動添加CUSTID屬性。 我相信這樣做很酷的方法是使用jQuery的Data函數。
但是我會如何在這種情況下使用它?
只是谷歌的JavaScript模板引擎或MVVM JavaScript框架。 – madfriend 2012-07-30 22:00:06
我以前使用過http://api.jquery.com/tmpl/。工作得很好。 – powerbuoy 2012-07-30 22:03:28
使用模板引擎並不會在js中串聯字符串而生成html。 – 2012-07-30 22:05:09