|
如下图所示:
我在数据表外部设置了一个按钮,点击执行一段代码,来实现将一个数组的数据写入到datatable中;
代码如下,但是,数据并未写入到数据表中,请问下该如何实现这个需求呢
var data = ["101", "102", "103"];
var table = document.getElementById("datatable");
data.forEach(function(value, index) {
var cell = document.getElementById("text" + (index + 1));
if (cell) {
var line = cell.parentElement.parentElement; // 假设行元素是cell的父元素的父元素
cell.textContent = value; // 将元素写入到单元格中
var module = line.getModule("text" + (index + 1)); // 获取对应模块
if (module) {
module.setData(cell.textContent);
} else {
console.error("No module with id 'text" + (index + 1) + "' found.");
}
} else {
console.error("No element with id 'text" + (index + 1) + "' found.");
}
});
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|