J'ai une table:obtenir des valeurs de la table sous forme de paires de valeurs-clés avec jquery
<table class="datatable" id="hosprates">
<caption> hospitalization rates test</caption> <thead>
<tr>
<th scope="col">Funding Source</th> <th scope="col">Alameda County</th> <th scope="col">California</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Medi-Cal</th>
<td>34.3</td>
<td>32.3</td>
</tr>
<tr>
<th scope="row">Private</th>
<td>32.2</td>
<td>34.2</td>
</tr>
<tr>
<th scope="row">Other</th>
<td>22.7</td>
<td>21.7</td>
</tr>
</tbody>
</table>
je veux récupérer la colonne 1 et la colonne 2 valeurs par ligne sous forme de paires qui finissent par ressembler à ce [financement, nombre] , [financement, nombre]
Je l'ai fait jusqu'à présent, mais quand je l'alerter, il montre seulement [objet, objet] ...
var myfunding = $('#hosprates tbody tr').each(function(){
var funding = new Object();
funding.name = $('#hosprates tbody tr td:nth-child(1)').map(function() {
return $(this).text().match(/\S+/)[0];
}).get();
funding.value= $('#hosprates tbody tr td:nth-child(2)').map(function() {
return $(this).text().match(/\S+/)[0];
}).get();
});
alert (myfunding);
salut mat, merci beaucoup mpler .. mais j'ai besoin des résultats retournés formatés comme je l'ai décrit ci-dessus ... est-ce que je ferais alors chaque une fonction sur result.name et result.value pour formater chaque paire? ou sur le résultat? – liz
@liz: Voir ma modifier :) – Matt
+1 Nice work :) – Mottie