0
我剛開始學習Mustache
,但我不明白我怎麼可以這樣做:與鬍鬚JS創建表
我有這個
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 };
我想創建this:
這是我嘗試過,但我不知道如何在每列上放置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);
如何創建上表?謝謝。