亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當我在表中插入日期對象時,JSON ajax 返回未定義

當我在表中插入日期對象時,JSON ajax 返回未定義

慕桂英4014372 2022-11-27 16:30:55
我試圖在表中插入元素,但在顯示數據對象時,出現未定義的消息如何將這個日期對象傳遞給表?其他對象沒問題,我只是數據對象有問題JSON:[  {    tipo: "O",    numero: "001",    data: { year: 2019, month: 4, day: 18 },    prazo: 0,    documento: "4600530888",  },];$.ajax({      url: 'buscaTextoAditivos.action', // action to be perform      type: 'POST',       //type of posting the data      data: { linhaSelecionadaJson: jsonHide }, // data to set to Action Class      dataType: 'json',      success: function (data) {      var indices = ['Tipo', 'Numero', 'Data', 'Prazo', 'Document']      var table = $("<table>")      var thead = $('<thead>')        for (const index of indices) {               $('<th>' + index + '</th>').appendTo(thead)            }               var tbody = $('<tbody>')                for (const item of data) {                     var tr = $('<tr>')                        for (const index of indices) {                            $('<td>' + item[index] + '</td>').appendTo(tr)                        }                        tr.appendTo(tbody)                    }                    tbody.appendTo(table)                  $("#loaderMaiorDemandante").hide();                  table.appendTo('#records_table')
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻1836條經驗 獲得超5個贊

您不需要兩個循環來遍歷值,您可以使用一個循環并訪問jsonusing中的所有值item.keyname,并訪問 json 數組 write 中的 json 對象item.data.keyname。


演示代碼:


//your response

var data = [{

    tipo: "O",

    numero: "001",

    data: {

      year: 2019,

      month: 4,

      day: 18

    },

    prazo: 1,

    documento: "4600530888"

  },

  {

    tipo: "O",

    numero: "001",

    data: {

      year: 2009,

      month: 4,

      day: 18

    },

    prazo: 0,

    documento: "4600530588"

  }

]

var indices = ['Tipo', 'Numero', 'Document', 'Prazo','Data']

var table = $("<table border='1'>")

var thead = $('<thead>')

for (const index of indices) {


  $('<th>' + index + '</th>').appendTo(thead)

}

var tbody = $('<tbody>')

for (const item of data) {

  var tr = $('<tr>')

  //get datas from json 

  $('<td>' + item.tipo + '</td>').appendTo(tr)

  $('<td>' + item.numero + '</td>').appendTo(tr)

  $('<td>' + item.prazo + '</td>').appendTo(tr)

  $('<td>' + item.documento + '</td>').appendTo(tr)

   $("<td>" + item.data.year + "/" + item.data.month + "/" + item.data.day + "</td>").appendTo(tr)

    tr.appendTo(tbody)


}

//apend data in thead 

thead.appendTo(table)

tbody.appendTo(table)


$("#loaderMaiorDemandante").hide();

table.appendTo('#records_table')

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id="records_table"></div>


查看完整回答
反對 回復 2022-11-27
  • 1 回答
  • 0 關注
  • 117 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號