How to batch modify the value of a single column in layui?
The following steps are required to use layui to batch modify the values of a single column:
- To retrieve the single column data to be edited: You can obtain the array of table data by accessing the data attribute of the table, for example: var data = table.cache.tableId;
- Iterate through the data array, modify the value of a specified column: You can use the forEach method or a for loop to iterate through the data array and perform a modification operation on each item, for example:
data.forEach(function(item){
item.columnName = newValue; // 修改指定列的值
});
Alternatively
for(var i = 0; i < data.length; i++){
data[i].columnName = newValue; // 修改指定列的值
}
- Refresh the data in the table with the specified table ID.
The complete example code is shown below:
var data = table.cache.tableId; // 获取表格数据
data.forEach(function(item){
item.columnName = newValue; // 修改指定列的值
});
table.reload('tableId', {data: data}); // 更新表格数据
Among them, tableId is the id attribute of the table, columnName is the column name to be modified, and newValue is the new value after modification.