项目中遇到关于对象数组的操作问题,大概是将数据绑定到Layui的Table中。由于layui表格的数据填充是按照它的格式需求填入的,比如目前我遇到的是:
cols: [[
{ field: 'index_col1', title: '序号', width: 66 },
{ field: 'stationName_col1', title: '站名',width: 106 },
{ field: 'temp_col1', title: '实时气温', width: 122.5, edit: 'text'},
{ field: 'index_col2', title: '序号', width: 66 },
{ field: 'stationName_col2', title: '站名', width: 106 },
{ field: 'temp_col2', title: '实时气温', width: 122.5, edit: 'text' },
{ field: 'index_col3', title: '序号', width: 66 },
{ field: 'stationName_col3', title: '站名', width: 106 },
{ field: 'temp_col3', title: '实时气温', width: 122.5, edit: 'text'}
]],
然后我获取到的数据大概是这样的:
data = [{ "index": "1", "stationName": "安吉1", "temp": "43" }, { "index": "1", "stationName": "安吉2", "temp": "23" }, {"index": "1", "stationName": "安吉3", "temp": "13" },
{ "index": "1", "stationName": "安吉4", "temp": "63" }, { "index": "1", "stationName": "安吉5", "temp": "43" }, {"index": "1", "stationName": "安吉6", "temp": "53" },
{ "index": "1", "stationName": "安吉7", "temp": "123" }, { "index": "1", "stationName": "安吉8", "temp": "33" }