javascript - jQuery + 从 json 创建表

标签 javascript jquery json

我有一个 JSON 文件

{
  "Scenario"    : "ModelNameHere",
  "id"          : "1",
  "description" : "Description of table model goes here",
  "headers"     : {
     "Column 1 header" : {
       "order"      : 1,
       "items"      : {
         "Row 1 Col 1 value" : {
           "id"         : 1,
           "comment"    : "Comment on Row 1 Col 1",
           "order"      : 1
         },
         "Row 2 Col 2 value" : {
           "id"         : 2,
           "comment"    : "Comment on Row 2 Col 2",
           "order"      : 2
         }
       }  
     },
     "Column 2 header" : {
       "order"      : 2,
       "items"      : {
         "Row 1 Col 2 value" : {
           "id"         : 3,
           "comment"    : "Comment on Row 1 Col 2",
           "order"      : 1
         },
             "Row 2 Col 2 value" : {
           "id"         : 4,
           "comment"    : "Comment on Row 2 Col 2",
           "order"      : 2
         }
       }  
     }
  }
}

我想使用 jQuery 将 JSON 数据放入 HTML 表格中。

标题应该放在 TH td 项中,标题中的项应该是每个相关行的 TD 中的元素。

JS 或 jQuery 中是否有函数可以用 JSON 数据填充表格?

我将如何遍历 JSON 元素并将其匹配到表格元素?

谢谢。

最佳答案

不,没有这样的函数,因为它是一个真正的特定于情境的函数。

虽然写起来很容易。
您可以将 JSON 作为普通的 JS 对象进行访问。
这意味着您可以遍历它并将信息放在正确的位置。

关于javascript - jQuery + 从 json 创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5271412/

相关文章:

javascript - AngularJS 延迟加载在 1.3.x 迁移后中断,获取参数 'XXCntr' 不是函数,未定义

jquery - 注入(inject)表单元素后重新加载 DOM?

javascript - 如何附加 jquery ui 自动完成元素?

javascript - 无法在 jquery 代码 ('#' + 添加上使用方法

javascript - 如何将字符串转换成json对象?

c# - c# 和 newtonsoft 中的 JSON 日期和日期时间序列化

javascript - 尝试在jquery中创建一个简单的视差效果

javascript - 在 Fancybox 的 Twitter 'tweet' 或 Facebook 'like' 中插入标题?

javascript - 正则表达式和数组 : Most efficient approach

json - ARM 模板 - 如何删除参数字符串中的空格?