更新时间:2023-11-19 18:23:34
icanhaz(小胡子)确实包含一种循环方法.
icanhaz (moustache) does include a way to loop.
在javascript中
In javascript:
var listOfStuff = {stuff: [
{key: "1", desc: "First"},
{key: "2", desc: "Second"}
]};
$("#mySelectBox").append(ich.myTemplate(listOfStuff));
您认为:
<script id="myTemplate" type="text/html">
{{#stuff}}
<option value="{{key}}">{{desc}}</option>
{{/stuff}}
</script>
<select id="mySelectBox">
</select>
{{#stuff}}
和{{/stuff}}
分隔列表.有关详细信息,请参见胡子的 Sections 部分.
The {{#stuff}}
and {{/stuff}}
delimit the list. Look at the Sections part of moustache for details.
确保检查出此答案如果您使用的是jQuery 1.9或更高版本.
Make sure to check out this answer if you're using jQuery 1.9 or above.