0

について学び始めたばかりですが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);

上記の表を作成するにはどうすればよいですか?ありがとうございました。

4

1 に答える 1

1

これがすぐにできるとは思いません。

現在持っている JSON オブジェクトを変更できない場合は、データをピボットして Mustache にフィードする別の JSON オブジェクトを生成することをお勧めします。

于 2013-07-25T23:15:22.673 に答える