Ich habe diese Tabelle, die eine Spalte hat, in der die Zelle möglicherweise einen Wert enthält oder nicht, aber wenn es das tut, ist es in einem JSON-Format; Ansonsten ist es leer (null).Objekt in einer Tabellenzelle schleifen und eine ungeordnete Liste erstellen
<table>
<tbody>
<tr>
<td>Barley</td>
<td>AK, AZ</td>
<td class="fpdCell">[{"date":"06/01/2016","error":"Double/Triple cropping","id":2},{"date":"06/07/2016","error":"Lack of Planting Dates Established","id":2}]</td>
<td>null</td>
</tr>
<tr>
<td>Barley</td>
<td>AK, AZ, AR</td>
<td class="fpdCell">[{"date":"06/04/2016","error":"No Error Found","id":3},{"date":"06/27/2016","error":"Lack of Planting Dates Established","id":3},{"date":"06/28/2016","error":"Weather Patterns","id":3}]</td>
<td>null</td>
</tr>
<tr>
<td>Burley Tobacco</td>
<td>null</td>
<td class="fpdCell">null</td>
<td>null</td>
</tr>
<tr>
<td>Fire Cured Tobbacco</td>
<td>null</td>
<td class="fpdCell">null</td>
<td>null</td>
</tr>
<tr>
<td>Flue Cured Tobacco</td>
<td>null</td>
<td class="fpdCell">null</td>
<td>null</td>
</tr>
<tr>
<td>Oats</td>
<td>null</td>
<td class="fpdCell">null</td>
<td>null</td>
</tr>
Was muss ich durch jede der Zellen mit dem fpdCell
Klasse, Schleife das Objekt innerhalb jedes dieser Zelle ist in einer Schleife tun, um eine Liste zu erstellen und sie als Listenelement hinzufügen.
Dies ist so weit wie ich konnte. Ich weiß wirklich nicht, wie ich mich von hier fortbewegen soll.
var theCells = $('.fpdCell');
$.each(theCells, function(index, value) {
var cellValues = $.parseJSON(value.textContent);
if (cellValues != 'null') {
console.log(cellValues);
value.textContent = '';
$(value).append('<ul class="list-group ul'+index+'"></ul>')
//then add <li class="list-group-item">Test</li>
//Not working------------------
/*
for (var u = 0; u < cellValues. length; u++) {
$('ul' + index).append('<li class="list-group-item">'+cellValues[u].date+'</li>');
console.log(cellValues[u].date);
}
*/
}
});
Vielen Dank im Voraus.
Danke. Dies war eine schwierige Entscheidung, alle Antworten funktionierten auf die eine oder andere Weise. Das einzige, was ich Ihrer Antwort hinzufüge, ist ein '$ el.text ('')', das in die Zelle geleert wird, bevor die Listenelemente eingefügt werden. – cubanGuy