0

I have a data stored in a json variable to list the categories and their subcategory if any. How can I write HTML code / HTML table in a json variable as I do for the data to display category name, description and so on in cells of a HTML table?

I want for example a table with 3 columns where I can write data (the key "text" of the json variable) in each of these columns. Even if writing the table for just one column would be useful to use a bootstrap data table to limit the entries per page.

var jsonVar = [{
  text: "Name: {{ category.name }}",
  icon: "fa fa-home fa-fw",
  nodes: [{
    text: "subcategory: {{ category.subcategory.name }}",
    icon: "fa fa-tree fa-fw",
    nodes: [{
      icon: "fa fa-user fa-fw",
      text: "Created By: {{ subactegory.createdBy}}"
    }]
  }]
}];

Thanks in advance for your comments.

Example:

isherwood
  • 58,414
  • 16
  • 114
  • 157
EE2017
  • 49
  • 11
  • You shouldn't be putting markup in json. That would be like storing an entire car in a gas can. Use json data to render markup using other code. – isherwood Oct 14 '22 at 18:16
  • FYI, your mention of the loop was an unnecessary distraction here. It's completely irrelevant how you construct your data. Whatever that was wasn't JavaScript anyway. – isherwood Oct 14 '22 at 18:22
  • If you _do_ actually want to store markup in your data, see https://stackoverflow.com/q/2522422/1264804. – isherwood Oct 14 '22 at 18:24
  • FYI again... this isn't really JSON anyway (unless you're transporting it as a string). It's just a JavaScript array. – isherwood Oct 14 '22 at 18:25
  • @isherwood this is the tree json data from the bootstrap treeview. Except from having static data in the json variable, my data are coming from the database, as I said my loop works perfectly. I just want to create a bootstrap data table in the variable so that I can take advantage of the search and limit the number of entries per page. – EE2017 Oct 15 '22 at 22:03

0 Answers0