隐藏来自JSON的第一列 [英] Hiding First Column coming from JSON

查看:64
本文介绍了隐藏来自JSON的第一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要带json数据并在成功调用时绑定.所以我的json如下

I am bringing the json data and binding on success call. So my json is as below

[{"APP_MST_ID":1.0,"APPLICATIONNAME":"LCO Mapping Application","URL":"Jiogis.ril.com/GraniteReverseIntegration//Test","PROJECTNO":"R4G-25-APD-128","VSSFOLDERLOC":"$/R4GGISNEPRODUCTION/128_LCO Mapping/02_Source_Code","SPOCUSER":"Prasad1.shinde","REQUESTEDBY":"Sanjive.kumar","DELIVERYMANAGER":"Jaganmohan.kudikala"}]

我想要的是,我想隐藏第一列APP_MST_ID和其值1.0.

What I want is, I want to hide the first column which is APP_MST_ID and its value which is 1.0.

我以以下格式绑定数据

success: function (data) {

  var html = '';

  if (data == "") {
    $("#dvTable").html('No Data Found');
  }

  else {
    var i = 0;

    var rData = JSON.parse(data);

    if (rData.length !== 0) {

      html += '<div class="table-responsive"><table class="table table-blue">';

      for (var key in rData) {

        var row = rData[key];

        if (key == 0) {
          html += '<tr>';
          for (var key2 in row) {
            html += '<th>';
            html += key2;
            html += '</th>';
          }
          html += '</tr>';
        }

        html += '<tr>';

        for (var key2 in row) {

          if (ddlSelectedVal == "Application") {
            if (i == 1) {
              html += "<td><a href=/Application/Index/" + row['APP_MST_ID'] + " class='menuCall'> " + row["APPLICATIONNAME"] + "</a></td>";
            }
            else {
              html += '<td>';
              html += row[key2];
            }
          }

          else if (ddlSelectedVal == "Services") {
            if (i == 1) {
              html += "<td><a href=/PlatformManager/Index/" + row['FOLDER_ID'] + " class='menuCall'> " + row["SERVICENAME"] + "</a></td>";
            }
            else {
              html += '<td>';
              html += row[key2];
            }
          }

          else {
            html += '<td>';
            html += row[key2];
          }

          i++;

          html += '</td>';
        }

        i = 0;
        html += '</tr>';
      }
      html += '</table></div>';
    }

    else {
      html += "No Data Found";
    }

    $("#dvTable").html(html);
  }
}

那么我怎么能隐藏该列及其值.请提出建议.

So how could I hide the column and its value. Please suggest.

推荐答案

第一个选项:只是不要将其包括在循环中.

First option: Just dont include it on your loop.

请注意,标头上有key2 != 'APP_MST_ID',不包含<th>

Notice on header there is key2 != 'APP_MST_ID' to not include the <th>

在正文上,您可以添加else if (i != 0)

And on the body, you can add else if (i != 0)

注意:确保APP_MST_ID是对象的第一个元素.

Note: make sure the APP_MST_ID is the first element of the object.

$(function() {
  var rData = [{
    "APP_MST_ID": 1.0,
    "APPLICATIONNAME": "LCO Mapping Application",
    "URL": "Jiogis.ril.com/GraniteReverseIntegration//Test",
    "PROJECTNO": "R4G-25-APD-128",
    "VSSFOLDERLOC": "$/R4GGISNEPRODUCTION/128_LCO Mapping/02_Source_Code",
    "SPOCUSER": "Prasad1.shinde",
    "REQUESTEDBY": "Sanjive.kumar",
    "DELIVERYMANAGER": "Jaganmohan.kudikala"
  }];
  var html = "";
  var ddlSelectedVal = "Application";
  var i = 0;

  html += '<div class="table-responsive"><table class="table table-blue">';

  for (var key in rData) {

    var row = rData[key];

    if (key == 0) {
      html += '<tr>';
      for (var key2 in row) {
        if (key2 != 'APP_MST_ID') {
          html += '<th>';
          html += key2;
          html += '</th>';
        }
      }
      html += '</tr>';
    }

    html += '<tr>';

    for (var key2 in row) {

      if (ddlSelectedVal == "Application") {
        if (i == 1) {
          html += "<td><a href=/Application/Index/" + row['APP_MST_ID'] + " class='menuCall'> " + row["APPLICATIONNAME"] + "</a></td>";
        } else if (i != 0) {
          html += '<td>';
          html += row[key2];
        }
      } else if (ddlSelectedVal == "Services") {
        if (i == 1) {
          html += "<td><a href=/PlatformManager/Index/" + row['FOLDER_ID'] + " class='menuCall'> " + row["SERVICENAME"] + "</a></td>";
        } else if (i != 0) {
          html += '<td>';
          html += row[key2];
        }
      } else {
        html += '<td>';
        html += row[key2];
      }

      i++;

      html += '</td>';
    }

    i = 0;
    html += '</tr>';
  }
  html += '</table></div>';

  $("#dvTable").html(html);

});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="dvTable"></div>

第二个选项:添加后使用jQuery隐藏

Second Option: Using jQuery hide after adding

$(function() {
  var rData = [{
    "APP_MST_ID": 1.0,
    "APPLICATIONNAME": "LCO Mapping Application",
    "URL": "Jiogis.ril.com/GraniteReverseIntegration//Test",
    "PROJECTNO": "R4G-25-APD-128",
    "VSSFOLDERLOC": "$/R4GGISNEPRODUCTION/128_LCO Mapping/02_Source_Code",
    "SPOCUSER": "Prasad1.shinde",
    "REQUESTEDBY": "Sanjive.kumar",
    "DELIVERYMANAGER": "Jaganmohan.kudikala"
  }];
  var html = "";
  var ddlSelectedVal = "Application";
  var i = 0;

  html += '<div class="table-responsive"><table class="table table-blue">';

  for (var key in rData) {

    var row = rData[key];

    if (key == 0) {
      html += '<tr>';
      for (var key2 in row) {
        html += '<th>';
        html += key2;
        html += '</th>';
      }
      html += '</tr>';
    }

    html += '<tr>';

    for (var key2 in row) {

      if (ddlSelectedVal == "Application") {
        if (i == 1) {
          html += "<td><a href=/Application/Index/" + row['APP_MST_ID'] + " class='menuCall'> " + row["APPLICATIONNAME"] + "</a></td>";
        } else {
          html += '<td>';
          html += row[key2];
        }
      } else if (ddlSelectedVal == "Services") {
        if (i == 1) {
          html += "<td><a href=/PlatformManager/Index/" + row['FOLDER_ID'] + " class='menuCall'> " + row["SERVICENAME"] + "</a></td>";
        } else {
          html += '<td>';
          html += row[key2];
        }
      } else {
        html += '<td>';
        html += row[key2];
      }

      i++;

      html += '</td>';
    }

    i = 0;
    html += '</tr>';
  }
  html += '</table></div>';

  $("#dvTable").html(html).promise().done(function() {
    var index = $("#dvTable table tr th:contains(APP_MST_ID)").index();
    $("#dvTable table tr th").eq(index).hide();
    $("#dvTable table tr td").eq(index).hide();
  });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="dvTable"></div>

这篇关于隐藏来自JSON的第一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆