gpt4 book ai didi

dart - 在 Dart 中添加表格行?

转载 作者:行者123 更新时间:2023-12-04 17:17:59 28 4
gpt4 key购买 nike

所以我决定从 Dart 开始,我已经在想用数据添加新表行的最佳方法是什么。

我尝试获取 tbody并使用其 children.add()使用 HTML 但它有问题,比如如果 tbody不存在。

最佳答案

在 JavaScript 中添加新的表格行时,您最终会遇到诸如没有 tbody 之类的问题。或者如何确定最后一行,但在 Dart 中我认为它更容易。

下面是一个例子:

enter image description here

import 'dart:html';

main() {
// Find the table.
TableElement table = query('#foo');

// Insert a row at index 0, and assign that row to a variable.
TableRowElement row = table.insertRow(0);

// Insert a cell at index 0, and assign that cell to a variable.
TableCellElement cell = row.insertCell(0);
cell.text = 'hey!';

// Insert more cells with Message Cascading approach and style them.
row.insertCell(1)
..text = 'foo'
..style.background = 'red';

row.insertCell(2)
..text = 'bar'
..style.background = 'green';
}

如果你想在最后插入一行,只需写:

table.insertRow(-1);

细胞也是如此。

关于dart - 在 Dart 中添加表格行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14011361/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com