私はJavaScriptの初心者なので、これに対する解決策は私が思っているよりも基本的かもしれません。このテーブルからデータを取得して配列で表示しようとしています。表は次のように始まります。
<table id="myTable">
<col>
<thead>
<tr>
<th>Date</th>
<th>Results1</th>
<th>Results2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Jan-00</td>
<td>9</td>
<td>10</td>
</tr>
<tr>
<td>Feb-00</td>
<td>92</td>
<td>64</td>
</tr>
そしてそこから続きます(それはたくさんの<tr>
'を含む長いテーブルです)。
変数を取得するための私のコードは、次のように始まります(これを支援するための他のソースへのヒント):
var columns = $('#myTable thead th').map(function() {
return $(this).text();
});
var tableObject = $('#myTable tr').map(function(i) {
var row = {};
// Find all of the table cells on this row.
$(this).find('td').each(function(i) {
// Determine the cell's column name by comparing its index
// within the row with the columns list we built previously.
var rowName = columns[i];
// Add a new property to the row object, using this cell's
// column name as the key and the cell's text as the value.
row[rowName] = $(this).text();
});
// Return the row's object representation, to be included
// in the array that $.map() ultimately returns.
return row;
// .get() to convert the jQuery set to a regular array.
}).get();
for (var i in tableObject) {
$.each(tableObject[i], function(key,value) {
var line1 = {};
line1[key] = value;
console.log(line1); //test
});
}
console.logテストでは、変数line1は、保持キーと値を次のように表示します:日付:Jan 00、Results1:9、Results2:10。
それはすべてうまくいっていますが、私は本当にこれらの値を次の形式で新しい配列に入れる必要があります。
var new = [[Date, Results1], [Date, Results2], etc...];
質問を繰り返しているのに、探していたものがまったく見つからなかった場合は、お詫び申し上げます。誰もが提供できるどんな助けにも本当に感謝します。