0

私はダートと遊んでいて、それが大好きですが、今は少し馬鹿げています。

この構造を持つhtmlページのテーブルに新しい行を追加しようとしています。

<table>
   <thead>
   ...
   </thead>
   <tbody>
   ...
   </tbody>
</table>

問題は、コードを実行すると、tbodyタグの後に新しい行が表示され、CSSスタイルが失われることです。

私はこのようにやっています:

TableElement myTable = query('#tabTest');
TableRowElement newLine = new TableRowElement();  
newLine.insertCell(0).text = "9";
newLine.insertCell(1).text = "aaa";
newLine.insertCell(2).text = "bbb";
newLine.insertCell(3).text = "ccc";
myTable.nodes.add(newLine);

これは間違っていますか?新しい行がtbodyタグ内に入るようにするにはどうすればよいですか?誰かが私に例を教えてもらえますか?

4

3 に答える 3

0

この変更をホスティングHTMLファイルに適用するだけです。

<table id="tabTest">
   <thead>
   </thead>
   <tbody id="tbody">
   </tbody>
</table>

そして、このダートコードへの変更:

//  TableElement myTable = query('#tabTest');
  var myTable = query('#tbody');
  TableRowElement newLine = new TableRowElement();
  newLine.insertCell(0).text = "9";
  newLine.insertCell(1).text = "aaa";
  newLine.insertCell(2).text = "bbb";
  newLine.insertCell(3).text = "ccc";
  myTable.nodes.add(newLine);
于 2012-07-31T19:53:10.540 に答える
0

Dartは、要素を構築するための多くの方法を提供します。あなたはこのようなことをすることができます:

void TableElement makeTable(List<String> ofStuff){
   final s = new StringBuffer();

   s.add('<table>');
   s.add('<thead></thead>');
   for(final stuff in ofStuff){
      s.add('<tr><td>${stuff}</td></tr>');
   }
   s.add('</table>');

   return new Element.html(s.toString()) as TableElement;
}
于 2012-07-31T22:02:18.913 に答える
0

私はこれを行うことによって私が望む結果を得ました:

TableElement myTable = query('#tabTest');
// add at the end
TableRowElement newLine = myTable.insertRow(myTable.rows.length); 
newLine.insertCell(0).text = "9";
newLine.insertCell(1).text = "aaa";
newLine.insertCell(2).text = "bbb";
newLine.insertCell(3).text = "ccc";
于 2012-08-01T13:06:43.423 に答える