Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在制表器中从json加载数据?_Javascript_Json_Tabulator - Fatal编程技术网

Javascript 在制表器中从json加载数据?

Javascript 在制表器中从json加载数据?,javascript,json,tabulator,Javascript,Json,Tabulator,我有这个json变量,希望通过制表器绘制表格: mydata= [ { "trade_symbol": "Media", "technical_sum_List": [ 19, 5, 4 ], "volume_sum_List": [ 6, 1 ], "pivot_sum_list": [ 5, 0, 0 ] }, { "tr

我有这个json变量,希望通过制表器绘制表格:

mydata=
[
  {
    "trade_symbol": "Media",
    "technical_sum_List": [
      19,
      5,
      4
    ],
    "volume_sum_List": [
      6,
      1
    ],
    "pivot_sum_list": [
      5,
      0,
      0
    ]
  },
  {
    "trade_symbol": "Sport",
    "technical_sum_List": [
      18,
      4,
      4
    ],
    "volume_sum_List": [
      3,
      4
    ],
    "pivot_sum_list": [
      5,
      0,
      0
    ]
  },
  {
    "trade_symbol": "Dance",
    "technical_sum_List": [
      13,
      10,
      5
    ],
    "volume_sum_List": [
      1,
      6
    ],
    "pivot_sum_list": [
      2,
      2,
      0
    ]
  }
]
现在我想通过制表器在每列中插入技术汇总表[1]或技术汇总表[2]。
在制表器中,我们只能使用字段:技术汇总表,不接受技术汇总表[1]

可能有更简单的方法,但您可以通过使用。要点是,在定义表列时,添加一个formatterParam,它告诉制表器要引用数组中的哪个索引以及自定义格式化程序函数的名称。定义一个单独的函数意味着您可以对所有阵列重用它

{title:"B-1", field:"technical_sum_List", formatterParams: {index:0}, formatter: customFormatter},
获取单元格值,然后使用formatterParams引用并返回该数组位置的数据

function customFormatter(cell, formatterParams) {
   return cell.getValue()[formatterParams.index];
}
让myData=[{ 贸易符号:媒体, 技术汇总表:[ 19, 5. 4. ], 卷和列表:[ 6. 1. ], 透视图和列表:[ 5. 0, 0 ] }, { 贸易标志:体育, 技术汇总表:[ 18, 4. 4. ], 卷和列表:[ 3. 4. ], 透视图和列表:[ 5. 0, 0 ] }, { 贸易符号:舞蹈, 技术汇总表:[ 13, 10, 5. ], 卷和列表:[ 1. 6. ], 透视图和列表:[ 2. 2. 0 ] } ] var table=新表格示例表格{ 身高:311磅, 栏目:[ {标题:A,字段:贸易符号}, {标题:B-1,字段:技术汇总表, formatterParams:{index:0}, 格式化程序:customFormatter}, {标题:B-2,字段:技术汇总表, formatterParams:{index:1}, 格式化程序:customFormatter}, {标题:B-3,字段:技术汇总表, formatterParams:{index:2}, 格式化程序:customFormatter}, ], }; 函数customFormattercell,formatterParams{ 返回cell.getValue[formatterParams.index]; } 表1.setDatamyData;
@spring是正确的,对于列绑定,只能遍历对象而不能遍历数组

@spring的方法可能有效,但您必须小心,因为过滤器和排序只能看到数组而不能看到数据

更好的方法可能是使用变异子,这样就可以让过滤器和分拣机访问数据。因此,我们可以使用@springs代码,并通过一些调整使其工作:

//定义变异体 函数customMutatorvalue、数据、类型、参数{ 返回数据[参数字段][参数索引]; } //为列指定mutator var table=新表格示例表格{ 身高:311磅, 栏目:[ {标题:A,字段:贸易符号}, {标题:B-1,字段:b1, mutatorParams:{索引:0,字段:technical_sum_List}, mutator:customMutator}, {标题:B-2,字段:b2, mutatorParams:{索引:1,字段:technical_sum_List}, mutator:customMutator}, {标题:B-3,字段:b3, mutatorParams:{索引:2,字段:technical_sum_List}, mutator:customMutator}, ], }; 这种方法有几个好处,它意味着可以对列进行排序和筛选,并将其包含在下载中

这也意味着现在每一列都有自己独特的字段,因此可以更容易地从表外查找

总之,格式化程序仅可视,不影响排序和筛选。另一方面,变异子会更新基础数据,并影响排序、筛选和其他一切

有关这方面的更多详细信息,请参见

谢谢

我找到了最好的答案: 我们必须使用格式化程序:customFormatter

        function customFormatter(cell, params) {
           return cell.getValue()[params.myid].rvalue;
        }
        
        
        for(var r=0;r<alldata[0].result.length;r++){
            table.addColumn({title:alldata[0].result[r].alias_title ,field:"result", formatterParams: {myid:r}, formatter: customFormatter});
        }