为了账号安全,请及时绑定邮箱和手机立即绑定

forEach遍历json数据填充表格,删除指定行。

forEach遍历json数据填充表格,删除指定行。

千巷猫影 2019-04-18 14:15:21
<!DOCTYPE html> <html>     <head>         <meta charset="UTF-8">         <title></title>         <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>     </head>     <body>         <table id='tab' border="1">             <thead>                 <tr style="background-color:#CCCCCC;">                     <th>名称</th>                     <th>数量</th>                     <th>价格</th>                 </tr>             </thead>             <tbody>             </tbody>         </table>     </body>     <script>         //水果数量         var fruit = {             '苹果': 0,             '香蕉': 2,             '水梨': 0,             '葡萄': 8,             '火龙果': 14,         }         var tianmao = [{                 id: 1,                 name: '橘子',                 price: 8             },             {                 id: 2,                 name: '香蕉',                 price: 8             },             {                 id: 3,                 name: '橘子',                 price: 8             },             {                 id: 4,                 name: '水梨',                 price: 8             },             {                 id: 5,                 name: '火龙果',                 price: 8             },             {                 id: 6,                 name: '葡萄',                 price: 8             }         ]         tianmao.forEach(function(obj) {             /*for(var i in tianmao) {                 for(var k in tianmao[i]) {                     if(tianmao[i][k] == "undefined") {                         //delete tianmao[i];                         tianmao.splice(i, 1);                         i = i - 1;                         break;                     }                 }             }*/通过遍历数据得到table如图,现在想删除掉数量未定义和为0的行tr,但实际table是带有分页得,方法一遍历不到所有得行(只能一页)行不通,怎么在append前,处理json得到想要得结果。谢谢十分~
查看完整描述

3 回答

?
狐的传说

TA贡献1804条经验 获得超3个赞

你在var str前面一行先加个判断不就行了吗


查看完整回答
反对 回复 2019-05-08
  • 3 回答
  • 0 关注
  • 680 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信