javascript提取兄弟姐妹,然后发送数据到django

时间:2014-04-23 12:48:35

标签: javascript jquery css django

我有点像

<tbody id="order_table">
       <tr class="list">
           <td data-status="old" class="food_name">food1</td>
           <td class="quantity">1</td>
           <td class="price">$10.00</td>
           <td><button type="button" class="btnIncrement btn"> <span class="fa fa-plus"></span></button></td>
       </tr>
       <tr class="list">
           <td data-status="old" class="food_name">food111</td>
           <td class="quantity">1</td>
           <td class="price">$10.00</td>
           <td><button type="button" class="btnIncrement btn"> <span class="fa fa-plus"></span></button></td>
       </tr>
       <tr class="list">
           <td data-status="new" class="food_name">food11</td>
           <td class="quantity">1</td>
           <td class="price">$10.00</td>
           <td><button type="button" class="btnIncrement btn"> <span class="fa fa-plus"></span></button></td>
       </tr>
       <tr class="list">
           <td data-status="new" class="food_name">food12</td>
           <td class="quantity">1</td>
           <td class="price">$10.00</td>
           <td><button type="button" class="btnIncrement btn"> <span class="fa fa-plus"></span></button></td>
       </tr>
 </tbody>

我想提取每个new项目的食物名称,数量和价格,并将它们放入数组,最后通过ajax发送到django .. 订单并不重要 这就是我想要的。

[[food11, 1, 10.00], [food12, 1, 10.00]]

如果不存在新项目,则返回

[]

我无法弄明白......所以我想要一些帮助。非常感谢你

1 个答案:

答案 0 :(得分:1)

var newFood = [];

$('#order_table td.food_name').filter(function() {
    return $(this).data('status') == 'new';
}).each(function() {
    newFood.push( [$(this).text(), $(this).siblings('.quantity').text(), $(this).siblings('.price').text()] );
});

$.ajax({
    // do you ajax
});