如何检查数据表中的条件?

时间:2018-12-26 05:23:58

标签: javascript jquery ajax datatable

我想检查数据表"data":"selectionAudit[0].assignFromDate"列中的条件并根据条件进行显示。

var table4 = $('#auditAndNonAudit').DataTable({
            "processing" : true,
            "scrollY": 100,
            "scrollX": true,
            "ajax" : {
                "url" : A_PAGE_CONTEXT_PATH + "/form/api/getAuditNonAuditSelection/all",
                dataSrc : ''
            },
            "columns" : [ {
                "data" : "selectionId"
            }, {
                "data" : "selectionDate"
            }, {
                "data" : "selectedBy"
            }, {
                "data" : "eximPanNo"
            }, {
                "data" : "eximPanName"
            }, {
                "data" : "eximPanAddr"
            }, {
                "data" : "eximPanPhone"
            }, {
                "data" : "selectionType"
            },{
                "data" : "auditorGroupName"
            },{
                "data":"selectionAudit[0].assignFromDate",
                mRender: function(data,type,row){
                    //data means id

                    if(data != null){

                        var str='';
                        str += '<a  class="fa fa-pencil" id="edit1"></a>';

                        str += '<a class="fa fa-trash" id="delete"></a>';

                        return str;
                    }

                    else{
                        alert("not");
                    }

                }
            } ]
        })

我的JSON数据是:

[  
   {  
      "selectionId":1,
      "selectionDate":"2075-09-27",
      "selectedBy":"Department",
      "eximPanNo":123456,
      "eximPanName":"aaaaaaaaaaa",
      "eximPanNameEng":"PCS",
      "eximPanAddr":null,
      "eximPanAddrEng":null,
      "eximPanPhone":9843709277,
      "selectionType":"consignment",
      "consignmentNo":4567889,
      "consignmentDate":"2075-09-26",
      "productName":null,
      "selectionFromDate":null,
      "selectionToDate":null,
      "agentNo":3454,
      "selectionStatus":"1",
      "entryBy":"1",
      "entryDate":"2018-12-25 11:49:26",
      "rStatus":"1",
      "custOfficeId":1,
      "selectionAudit":[  
         {  
            "audGrpId":2,
            "selectionId":1,
            "assignFromDate":"2075-09-18",
            "assignToDate":"2075-09-27",
            "entryBy":"1",
            "rStatus":"1"
         }
      ],
      "letter":null,
      "auditorGroupName":"CC",
      "document":null,
      "assessment":null,
      "assessCatAmount":null
   },
   {  
      "selectionId":2,
      "selectionDate":"2075-09-03",
      "selectedBy":"Department",
      "eximPanNo":233,
      "eximPanName":"233",
      "eximPanNameEng":"card",
      "eximPanAddr":null,
      "eximPanAddrEng":null,
      "eximPanPhone":983764366278,
      "selectionType":"product",
      "consignmentNo":1,
      "consignmentDate":"2075-09-11",
      "productName":null,
      "selectionFromDate":"2075-09-11",
      "selectionToDate":"2075-09-04",
      "agentNo":12,
      "selectionStatus":"1",
      "entryBy":"1",
      "entryDate":"2018-12-25 12:47:04",
      "rStatus":"1",
      "custOfficeId":1,
      "selectionAudit":null,
      "letter":null,
      "auditorGroupName":null,
      "document":null,
      "assessment":null,
      "assessCatAmount":null
   }
]

selectionId = 2的数据selectionAudit[0].assignFromDate为空,因此应该转到其他部分,但不会继续。在这里,我应用了IF条件来检查数据表中的条件,但它没有进入其他部分。

{
                "data":"selectionAudit[0].assignFromDate",
                mRender: function(data,type,row){
                    //data means id

                    if(data != null){

                        var str='';
                        str += '<a  class="fa fa-pencil" id="edit1"></a>';

                        str += '<a class="fa fa-trash" id="delete"></a>';

                        return str;
                    }

                    else{
                        alert("not");
                    }

                }
            }

1 个答案:

答案 0 :(得分:1)

而不是检查if(data != null) { }

就像

一样检查
if(data) { } else { }