开发者

Group Table Rows into an array

I need to group a variable amount of table rows into an array. Each group has 5 cells as shown in the HTML:

<tr> 
<td width='23%' class='table-item-1'><strong>EVP</strong></td> 
<td width='15%' class='table-item-1'>Diane</td> 
<td width='17%' class='table-item-1'>xxx-xxx-xxxx</td> 
<td width='17%' class='table-item-1'>xxx-xxx-6xxx</td> 
<td width='25%' class='table-item-1'>&nbsp;<a href='mailto:'></a></td> 
</tr> 
<tr> 
<td width='23%' class='table-item-1'><strong>EVP</strong></td> 
<td width='15%' class='table-item-1'>Leslee</td> 
<td width='17%' class='table-item-1'>xxx-xxx-xxxx</td> 
<td width='17%' class='table-item-1'>xxx-xxx-6xxx</td> 
<td width='25%' class='table-item-1'>&nbsp;<a href='mailto:'></a></td> 
</tr> 
<tr> 
<td width='23%' class='table-item-1'><strong>Production Mgr</strong></td> 
<td width='15%' class='table-item-1'><s>Lenny  </s>&nbsp; tbh</td> 
<td width='17%' class='table-item-1'>xxx-xxx-xxxx</td> 
<td width='17%' class='table-item-1'>xxx-xxx-6xxx</td> 
<td width='25%' class='table-item-1'>&nbsp;<a href='mailto:'></a></td> 
</tr> 
<tr> 
<td width='23%' class='table-item-1'><strong>Production</strong></td> 
<td width='15%' class='table-item-1'>Jessica</td> 
<td width='17%' class='table-item-1'>xxx-xxx-xxxx</td> 
<td width='17%' class='table-item-1'>xxx-xxx-2xxx</td> 
<td width='25%' class='table-item-1'>&nbsp;<a href='mailto:'></a></td> 
</tr>

Here is what I have so far:

var items_size = $('[width|="23%"]').size(); //gives me the amount of groups

var items1 = {   
        'name': $('.table-item-1 ~ td').html(),
        'email': $('.table-item-1 ~ td > a').html(),
        'phone': $('.table-item-1 ~ td').next().html(),
        'fax': $('.table-item-1 ~ td').next().next().html(),
        'title': $('.table-item-1 ~ td').prev().children().html()
        }; // creates an array co开发者_如何学编程ntaining the items from the first group.

I need to create the same array for each group in the HTML.


var items = [];
$('table tr').each(function () {
  // access each tr's tds from here using $(this)
  var item = {
       'name' : $(this).find('td:first').text(),
       ...
  }
  items.push(item);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜