你可以用一个助手来做到这一点:http: //jsfiddle.net/imsky/B8ks2/
<script id="jsRendTmp" type="text/x-jquery-tmpl">
<div style="margin:10px 0">Title</div>
{{for ~getFields()}}
<li>{{>key}}: {{>value}}</li>
{{/for}}
</script>
var data = [ { "Field ID": "22", dtTime: "8/1/2021" }, { "Field ID": "33", dtTime: "8/2/2021" } ];
$.views.helpers({
getFields: function( object) {
var object = this.data;
var key, value,
fieldsArray = [];
for ( key in object ) {
if ( object.hasOwnProperty( key )) {
value = object[ key ];
// For each property/field add an object to the array, with key and value
fieldsArray.push({
key: key,
value: value
});
}
}
// Return the array, to be rendered using {{for ~fields(object)}}
return fieldsArray;
}
});
$("#content").html($("#jsRendTmp").render(data));