【发布时间】:2021-04-21 05:55:13
【问题描述】:
如果可以在加载到Tabulator library 中的表之前修改表数据,我需要帮助。 我需要将(8 极)DIP 开关的十进制值转换为单独的 8 位并将其加载到表中。 我有这样的 json 格式的数据:
[
{"id":1, "name":"DIP1", "value":15},
{"id":2, "name":"DIP2", "value":75}
]
我想把数据格式化成这个(十进制值 15):
[{"id":1, "name":"DIP1", "sw1":0,"sw2":0,"sw3":0,"sw4":0,"sw5":1,"sw6":1,"sw7":1,"sw8":1,}]
到这张桌子:
columns:[
{ title:'ID', field:'id', width:50 },
{ title:'DIP NAME', field:'name', headerFilter:'input', editor:'input', hozAlign:'center' },
{ title:' DIP SWITCHES', hozAlign:'center',
columns:[
{ title:'SW1', field:'sw1', width:30, hozAlign:'center', editor:true, formatter:'tickCross', headerVertical:true, headerFilter:'tickCross', headerFilterParams:{"tristate":true}, headerSort:false },
{ title:'SW2', field:'sw2', width:30, hozAlign:'center', editor:true, formatter:'tickCross', headerVertical:true, headerFilter:'tickCross', headerFilterParams:{"tristate":true}, headerSort:false },
{ title:'SW3', field:'sw3', width:30, hozAlign:'center', editor:true, formatter:'tickCross', headerVertical:true, headerFilter:'tickCross', headerFilterParams:{"tristate":true}, headerSort:false },
{ title:'SW4', field:'sw4', width:30, hozAlign:'center', editor:true, formatter:'tickCross', headerVertical:true, headerFilter:'tickCross', headerFilterParams:{"tristate":true}, headerSort:false },
{ title:'SW5', field:'sw5', width:30, hozAlign:'center', editor:true, formatter:'tickCross', headerVertical:true, headerFilter:'tickCross', headerFilterParams:{"tristate":true}, headerSort:false },
{ title:'SW6', field:'sw6', width:30, hozAlign:'center', editor:true, formatter:'tickCross', headerVertical:true, headerFilter:'tickCross', headerFilterParams:{"tristate":true}, headerSort:false },
{ title:'SW7', field:'sw7', width:30, hozAlign:'center', editor:true, formatter:'tickCross', headerVertical:true, headerFilter:'tickCross', headerFilterParams:{"tristate":true}, headerSort:false },
{ title:'SW8', field:'sw8', width:30, hozAlign:'center', editor:true, formatter:'tickCross', headerVertical:true, headerFilter:'tickCross', headerFilterParams:{"tristate":true}, headerSort:false },
],
}
],
我知道如何提取 c 中的每一位:
var sw1 = bitRead( value, 7 );
var sw2 = bitRead( value, 6 );
var sw3 = bitRead( value, 5 );
var sw4 = bitRead( value, 4 );
var sw5 = bitRead( value, 3 );
var sw6 = bitRead( value, 2 );
var sw7 = bitRead( value, 1 );
var sw8 = bitRead( value, 0 );
但我不知道如何在使用 ajax 将数据加载到表中时执行此操作。
有人可以帮忙吗?
我是新手,无法自拔。
谢谢!
【问题讨论】:
标签: javascript tabulator