【问题标题】:Extract field from nested JSON object从嵌套的 JSON 对象中提取字段
【发布时间】:2021-02-10 03:41:20
【问题描述】:

我有一个 JSON 结果集,其中每一行都包含嵌套的 JSON 对象。有没有办法将表中的列定义为“object.field”?

【问题讨论】:

    标签: tabulator


    【解决方案1】:

    是的,您完全可以这样做。假设您的行数据如下所示:

    {
        id:1,
        user:{
            name:"steve",
            age:23
        },
        col:"red",
        cheese:true
    }
    

    如果您想设置一个列以查看用户对象的名称属性,您可以将该字段设置为user.name

    var table = new Tabulator("#example-table", {
        columns:[
            {title:"Name", field:"user.name"},  //link column to name property of user object
        ],
    });
    

    查看Nested Data Documentation 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      • 1970-01-01
      • 2021-10-04
      • 2021-12-21
      • 1970-01-01
      相关资源
      最近更新 更多