jquery 中each 用法,進行if條件判斷,如果異常設置單元格的背景色


在前台頁面:
                    //需求數量和招標數量sumapplyamount  sumamount
                    //招標和定標sumamount  sumawardingamount
                    //定標總數量和下達訂單總數量sumawardingamount summenge
rowData 相當於數組對象
rowBound: function (jqRow, rowData, index, pageIndex) {
             
                  
                    $.each(rowData, function (i, val) {
                       alert(i);
                        //alert(val);
                    });

遍歷數組 怎么進行if()條件進行判斷,判斷條件是 上面三點,然后如果判斷不通過,設置單元格的背景顏色
求大神。
數據有很多行

15 个解决方案

#1


alert(i)  是 鍵  打印出來 類似 id ,name ,age,
alert(val)  是值  打印出來 類似  1,“哈哈”,18 

#2


  $.each(rowData, function (i, val) { 
                        alert(rowData['sumawardingamount']);
                        alert(rowData['summenge']);
                        if(rowData['sumawardingamount']!=rowData['summenge'])
                        {
                            alert("異常03");
                        }
                       
                    })

怎么將異常03出設置該單元格的背景色為紅色

#3


rowData是什么數組?
$(rowData[i]).css('background-color','#F00')

#4


$("#table表格id tr").eq(i).css('background-color','#F00')

#5


引用 3 樓 xiaojunjor 的回復:
rowData是什么數組?
$(rowData[i]).css('background-color','#F00')



     rowBound: function (jqRow, rowData, index, pageIndex) {
                if (rowData.isabnormal == "yes") {
                    //jqRow.css({ 'background-color': '#FA8072' });
                    jqRow.css({ 'background-color': '' });
                    //需求數量和招標數量sumapplyamount  sumamount
                    //招標和定標sumamount  sumawardingamount
                    //定標總數量和下達訂單總數量sumawardingamount summenge
                    $.each(jqRow, function (i, val) {
                        alert(i);
                        alert(val);
                    });
                    /*
                        $.each(rowData, function (i, val) { 
                            alert(rowData['sumawardingamount']);
                            alert(rowData['summenge']);
                            if(rowData['sumawardingamount']!=rowData['summenge'])
                            {
                                alert("異常03");
                            }
                        });*/

前台設置斷點后:
rowDate是當前行數據  rowData = Object {id: "00000000-0000-0000-0000-000000000000", projecttime: "20170816", sapproductid: "000000006021010223"
jqRow 應該是行   jqRow = [tr],  jqRow打印類型類型是object HTMLTableRowElement


求大神,沒弄出來

#6


引用 4 樓 jslang 的回復:
$("#table表格id tr").eq(i).css('background-color','#F00')



     rowBound: function (jqRow, rowData, index, pageIndex) {
                if (rowData.isabnormal == "yes") {
                    //jqRow.css({ 'background-color': '#FA8072' });
                    jqRow.css({ 'background-color': '' });
                    //需求數量和招標數量sumapplyamount  sumamount
                    //招標和定標sumamount  sumawardingamount
                    //定標總數量和下達訂單總數量sumawardingamount summenge
                    $.each(jqRow, function (i, val) {
                        alert(i);
                        alert(val);
                    });
                    /*
                        $.each(rowData, function (i, val) { 
                            alert(rowData['sumawardingamount']);
                            alert(rowData['summenge']);
                            if(rowData['sumawardingamount']!=rowData['summenge'])
                            {
                                alert("異常03");
                            }
                        });*/

前台設置斷點后:
rowDate是當前行數據  rowData = Object {id: "00000000-0000-0000-0000-000000000000", projecttime: "20170816", sapproductid: "000000006021010223"
jqRow 應該是行   jqRow = [tr],  jqRow打印類型類型是object HTMLTableRowElement

#7


引用 3 樓 xiaojunjor 的回復:
rowData是什么數組?
$(rowData[i]).css('background-color','#F00')


rowData 是整行數據,如果其中2個判斷異常,將第二個單元格的背景色設置紅色,不是設置整行
設置整行
可以通過   jqRow.css({ 'background-color': '#FA8072' });

#8


引用 7 樓 qq_34745652 的回復:
Quote: 引用 3 樓 xiaojunjor 的回復:

rowData是什么數組?
$(rowData[i]).css('background-color','#F00')


rowData 是整行數據,如果其中2個判斷異常,將第二個單元格的背景色設置紅色,不是設置整行
設置整行
可以通過   jqRow.css({ 'background-color': '#FA8072' });


  jqRow.find("td").eq(i).css({ 'background-color': '#FA8072' });


#9


引用 4 樓 jslang 的回復:
$("#table表格id tr").eq(i).css('background-color','#F00')



在判斷條件異常后,給異常字段的單元格設置背景色,
jqRow.css({ 'background-color': '#FA8072' });

引用 8 樓 jslang 的回復:
Quote: 引用 7 樓 qq_34745652 的回復:

Quote: 引用 3 樓 xiaojunjor 的回復:

rowData是什么數組?
$(rowData[i]).css('background-color','#F00')


rowData 是整行數據,如果其中2個判斷異常,將第二個單元格的背景色設置紅色,不是設置整行
設置整行
可以通過   jqRow.css({ 'background-color': '#FA8072' });


  jqRow.find("td").eq(i).css({ 'background-color': '#FA8072' });




 $.each(rowData, function (i, val) { 
                            //alert(rowData['sumawardingamount']);
                            //alert(rowData['summenge']);
                            if(rowData['sumawardingamount']!=rowData['summenge'])
                            {
                                //$(jqRow.summenge)
                                jqRow.find("td").eq(i).css({ 'background-color': '#FA8072' });
                                alert("異常03");
                            }
                        });



引用 8 樓 jslang 的回復:
Quote: 引用 7 樓 qq_34745652 的回復:

Quote: 引用 3 樓 xiaojunjor 的回復:

rowData是什么數組?
$(rowData[i]).css('background-color','#F00')


rowData 是整行數據,如果其中2個判斷異常,將第二個單元格的背景色設置紅色,不是設置整行
設置整行
可以通過   jqRow.css({ 'background-color': '#FA8072' });


  jqRow.find("td").eq(i).css({ 'background-color': '#FA8072' });




      rowBound: function (jqRow, rowData, index, pageIndex) {
                if (rowData.isabnormal == "yes") {
                    //jqRow.css({ 'background-color': '#FA8072' });
                    jqRow.css({ 'background-color': '' });
                    //需求數量和招標數量sumapplyamount  sumamount
                    //招標和定標sumamount  sumawardingamount
                    //定標總數量和下達訂單總數量sumawardingamount summenge
                   /* $.each(jqRow, function (i, val) {
                        alert(i);
                        alert(val);
                    });*/
                    
                        $.each(rowData, function (i, val) { 
                            //alert(rowData['sumawardingamount']);
                            //alert(rowData['summenge']);
                            if(rowData['sumawardingamount']!=rowData['summenge'])
                            {
                                //$(jqRow.summenge)
                                jqRow.find("td").eq(i).css({ 'background-color': '#FA8072' });
                                alert("異常03");
                            }
                        });

rowBound是填充每行數據,現在是實現 如果rowData['sumawardingamount']!=rowData['summenge'] 這個條件成立
把當前行  一個單元格 改變為紅色,有三個判斷條件。

#10


rowData是一行的數據,那你還用each循環個什么,每次循環中if判斷的不都一樣么

#11


引用 10 樓 jslang 的回復:
rowData是一行的數據,那你還用each循環個什么,每次循環中if判斷的不都一樣么



這我知道,就是不知道怎么找到對應的td然后標注為紅色     
if (rowData.sumapplyamount != rowData.sumamount)
                    {
                        alert("異常01");
                        怎么找到對應的單元格變成紅色背景色
                    }

#12


引用 10 樓 jslang 的回復:
rowData是一行的數據,那你還用each循環個什么,每次循環中if判斷的不都一樣么

怎么能找到對應的單元格,因為有三個判斷條件,

$(jqRow).find("td").css({ 'background-color': '#FA8072' });這樣是把異常整行的標記為紅色,
用選擇器也定位不到,

#13


</thead>
                <tbody id="totaltablerows">
                    <script type="text/template">
                        <tr>
                            <td><span data-field="projecttime"></span></td>
                            <td><span data-field="sapproductid"></span></td>
                            <td><span data-field="productname"></span></td>
                            <td><span class="sumapplyamount" data-field="sumapplyamount"></span></td>
                            <td><span class="sumamount" data-field="sumamount"></span></td>
                            <td><span class="sumawardingamount" data-field="sumawardingamount"></span></td>
                            <td><span class="summenge" data-field="summenge"></span></td>
                        </tr>
                    </script>

這是table表單

#14


你這是判斷已知的屬性,不需要循環,類似下面的形式。如果判斷的屬性不對自己改一下

      rowBound: function (jqRow, rowData, index, pageIndex) {
                if (rowData.isabnormal == "yes") {
                    //jqRow.css({ 'background-color': '#FA8072' });
                    jqRow.find("td").css({ 'background-color': '' });
                    //需求數量和招標數量sumapplyamount  sumamount
                    //招標和定標sumamount  sumawardingamount
                    //定標總數量和下達訂單總數量sumawardingamount summenge
                    if(rowData['sumapplyamount']!=rowData['sumamount'])
                    {
                        jqRow.find("td").eq(3).css({ 'background-color': '#FA8072' });
                    }
                     if(rowData['sumamount']!=rowData['sumawardingamount'])
                    {
                        jqRow.find("td").eq(4).css({ 'background-color': '#FA8072' });
                    }
                     if(rowData['sumawardingamount']!=rowData['summenge'])
                    {
                        jqRow.find("td").eq(5).css({ 'background-color': '#FA8072' });
                    }
                }


#15


引用 12 樓 qq_34745652 的回復:
Quote: 引用 10 樓 jslang 的回復:

rowData是一行的數據,那你還用each循環個什么,每次循環中if判斷的不都一樣么

怎么能找到對應的單元格,因為有三個判斷條件,

$(jqRow).find("td").css({ 'background-color': '#FA8072' });這樣是把異常整行的標記為紅色,
用選擇器也定位不到,

</thead>
                <tbody id="totaltablerows">
                    <script type="text/template">
                        <tr>
                            <td><span data-field="projecttime"></span></td>
                            <td><span data-field="sapproductid"></span></td>
                            <td><span data-field="productname"></span></td>
                            <td><span class="sumapplyamount" data-field="sumapplyamount"></span></td>
                            <td><span class="sumamount" data-field="sumamount"></span></td>
                            <td><span class="sumawardingamount" data-field="sumawardingamount"></span></td>
                            <td><span class="summenge" data-field="summenge"></span></td>
                        </tr>
                    </script>

table  表單

引用 14 樓 jslang 的回復:
你這是判斷已知的屬性,不需要循環,類似下面的形式。如果判斷的屬性不對自己改一下

      rowBound: function (jqRow, rowData, index, pageIndex) {
                if (rowData.isabnormal == "yes") {
                    //jqRow.css({ 'background-color': '#FA8072' });
                    jqRow.find("td").css({ 'background-color': '' });
                    //需求數量和招標數量sumapplyamount  sumamount
                    //招標和定標sumamount  sumawardingamount
                    //定標總數量和下達訂單總數量sumawardingamount summenge
                    if(rowData['sumapplyamount']!=rowData['sumamount'])
                    {
                        jqRow.find("td").eq(3).css({ 'background-color': '#FA8072' });
                    }
                     if(rowData['sumamount']!=rowData['sumawardingamount'])
                    {
                        jqRow.find("td").eq(4).css({ 'background-color': '#FA8072' });
                    }
                     if(rowData['sumawardingamount']!=rowData['summenge'])
                    {
                        jqRow.find("td").eq(5).css({ 'background-color': '#FA8072' });
                    }
                }




太感謝 ,明白了明白了,eq的意思是?

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com