Cosmin
Cosmin

Reputation: 2214

Creating table with Mustache JS

I've just started to learn about Mustache, but I don't understand how can I do this:

This is what I've tried, but I don't know how to put values on each column, not on each row.

    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);

How can I create the table above? Thank you.

Upvotes: 0

Views: 1286

Answers (1)

rivarolle
rivarolle

Reputation: 1538

I don't believe this can be done out of the box.

If you can't modify the JSON object that you currently have, you're better off generating another JSON object that will pivot the data and feed that one to Mustache.

Upvotes: 1

Related Questions