[英]Jquery Array To Table “TD”
I have an array (created dynamically) that would look like [one,two,three,four,five,six] 我有一个数组(动态创建),看起来像[一个,两个,三个,四个,五个,六个]
I have a table (created dynamically) with the same number of rows as items in the array 我有一个表(动态创建),表的行数与数组中的项相同
<table>
<tr>
<td><td>
<td>content</td>
</tr>
<tr>
<td><td>
<td>content</td>
</tr>
<tr>
<td><td>
<td>content</td>
</tr>
<tr>
<td><td>
<td>content</td>
</tr>
<tr>
<td><td>
<td>content</td>
</tr>
<tr>
<td><td>
<td>content</td>
</tr>
</table>
My goal, is to place the array item in the td:first-of-type in the row with the corresponding index() value as array position. 我的目标是将数组项放在行的td:first-of-type中,并将相应的index()值作为数组位置。
I generally dont ask question this early on, but I'm clueless on how to go about doing this. 我通常不提早问这个问题,但是我对如何做到这一点一无所知。 This one is a little over my head?
这一点有点让我烦恼吗?
each
gives everything to you almost out-of-the-box: each
都几乎为您提供了开箱即用的所有功能:
$("tr").each(function(index, elem){
$(this).find("td").first().text(yourArray[index]);
})
Ok, maybe loop through them like this: 好的,也许像这样遍历它们:
$("table tr").each(function(index) {
$(this).children("td").first().html(myArray[index]);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.