javascript - 使用 json2html 将 json 对象转换为 html 表

标签 javascript jquery html json

我在使用 json2html 时遇到问题 https://github.com/eisenbraun/columns图书馆 。是否可以将此 js 库与 Json 对象一起使用,如下所示。

var jsonobj = [{
  "id": "31",
  "Mesial": {
    "disorder": "",
    "other": ""
  },
  "Facial": {
    "disorder": "DC-HP",
    "other": ""
  },
  "Distal": {
    "disorder": "",
    "other": ""
  },
  "Lingual": {
    "disorder": "",
    "other": ""
  },
  "Occlusal": {
    "disorder": "",
    "other": ""
  }
}, {
  "id": "37",
  "Mesial": {
    "disorder": "",
    "other": ""
  },
  "Facial": {
    "disorder": "RE-AR",
    "other": ""
  },
  "Distal": {
    "disorder": "",
    "other": ""
  },
  "Lingual": {
    "disorder": "",
    "other": ""
  },
  "Occlusal": {
    "disorder": "",
    "other": ""
  }
}]  

我使用过在线工具Convert JSON to HTML Table ,但不幸的是它的库不可用。

预期的表输出是

快照 enter image description here

最佳答案

不,您的数据格式不正确。

您的格式需要尊重其数据格式:

[{"col1":"row1", "col2":"row1", "col3":"row1"}, {"col1":"row2", "col2":"row2", "col3":"row2"}]

每个对象都有一个 colX:rowY 格式。

所以你不能将对象作为行条目。

关于javascript - 使用 json2html 将 json 对象转换为 html 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53205962/

相关文章:

Javascript 自定义表格列的能力。允许用户删除和添加新列的按钮

javascript - 使用一个 jQuery AJAX 表单(或响应)返回两个数据库结果

Javascript 无限循环遍历数组不起作用

javascript - 无法弄清楚为什么名称没有出现在 div 中

html - 如何为响应式网站设置最小和最大宽度的 CSS 样式?

Javascript:替换文本区域中突出显示的字符串?

javascript全局变量问题

html - flex 属性在 IE 中不起作用

javascript - 剑道网格增删改查 : how make update

javascript - 添加 jQuery 验证方法时 this.optional(element) 做了什么?