我刚刚开始了解Mustache
,但我不明白我该怎么做:
我有这个
JSON
对象:var columnsDefinition = { "columns": [ { "header": 'First name', "values": ['John', 'Jack', 'Abe', 'Adelle', 'Jim', 'Andrew', 'Matthew'], "type": 'text' }, { "header": 'Last name', "values": ['Carpenter', 'Reaper', 'Lincoln', 'Aidan', 'Raynor', 'Doe'], "type": 'text' }, { "header": 'Profession', "values": ['butcher', 'doctor', 'farmer', '', 'pilot', 'singer', ''], "type": 'select' }, { "header": 'Employed', "values": [true, false, true, true, false], "type": 'checkbox' } ], "search": true };
我想创建这个:
这是我尝试过的,但我不知道如何放在 values
每一列,而不是每一行。
this.testDiv = $("#testDiv");
this.header = "{{#columns}}<th>{{header}}</th>{{/columns}}";
this.body = "{{#columns}}<tr>{{#values}}<td>{{.}}</td><{{/values}}/tr>{{/columns}}";
this.html = Mustache.to_html(this.header, this.columnsDefinition);
this.html2 = Mustache.to_html(this.body, this.columnsDefinition);
$("#testDiv table thead tr").append(this.html);
$("#testDiv table tbody").append(this.html2);
如何创建上面的表格?谢谢你。