第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

從 Javascript 數(shù)組生成動(dòng)態(tài) HTML 表

從 Javascript 數(shù)組生成動(dòng)態(tài) HTML 表

PHP
牛魔王的故事 2023-09-15 21:37:29
我目前正在使用 php、javascript 和 html 制作一個(gè)網(wǎng)絡(luò)應(yīng)用程序。我對(duì) php 進(jìn)行 HTTP 后調(diào)用,以從數(shù)據(jù)庫(kù)中獲取必須在 html 表中顯示的信息。我從我的 post http 調(diào)用中得到以下數(shù)據(jù):0:DwgFile: "\\TEAM\wwwroot\dwfs\A-104589 ELEVATOR FRAME ASS'Y.idw.dwf"DwgNo: "2A"IssueDate: "2020-05-30"IssueEMID: 10709ItemID: 232002ItemNo: "A-104589"OrderID: 13352Qty Total: 1ShortDesc: "ELEVATOR FRAME ASS'Y"SolidFile: "\\TEAM\wwwroot\dwfs\A-104589 ELEVATOR FRAME ASS'Y.iam.dwf"_DwgNo: 2__proto__: Object1:DwgFile: "\\TEAM\wwwroot\dwfs\A-104599 DRIVE SHAFT ASS'Y.idw.dwf"DwgNo: "3A"IssueDate: "2019-12-12"IssueEMID: 10710ItemID: 232012ItemNo: "A-104599"OrderID: 13352Qty Total: 1ShortDesc: "DRIVE SHAFT ASS'Y"SolidFile: "\\TEAM\wwwroot\dwfs\A-104599 DRIVE SHAFT ASS'Y.iam.dwf"_DwgNo: 3如何在 html 表的一行中顯示數(shù)組中的每個(gè)索引。數(shù)組中的每個(gè)屬性都將是表中的一列。我需要該表是動(dòng)態(tài)的,因?yàn)閿?shù)組中的索引數(shù)量將根據(jù)用戶的輸入而變化。任何幫助深表感謝。干杯!編輯這就是表格應(yīng)該看起來(lái)類(lèi)似的內(nèi)容
查看完整描述

1 回答

?
慕沐林林

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊

首先,使用 HTML 創(chuàng)建一個(gè)空表。


<table id="dynamic_table"></table>

接下來(lái),我們可以使用 jQuery 填充表格。


var data_from_post = ...


//create head by looping through keys of first object in result

var table_head = $('<tr></tr>').wrap('<thead></thead>');

$.each(data_from_post[0], function(key) {

  table_head.append('<th>' + key + '</th>');

});


//create body by looping through each result, then looping through each key in that result

var table_body = $('<tbody></tbody>');

$.each(data_from_post, function(index, values) {

    var row = $('<tr></tr>');

    $.each(values, function(key, value) {


        //here you can perform changes to the 'value' variable if you need it to be different in the table

        //for example, wrap the `_DwgNo` with a button

        if(key == '_DwgNo') {

            value = '<button>' + value + '</button>'

        }


        row.append('<td>' + value + '</td>');

    });

    table_body.append(row);

});


//add the head and body to the table

$('#dynamic_table').append(table_head).append(table_body);

這是包含此解決方案的 jsfiddle


https://jsfiddle.net/2Lon5vj3/1/


查看完整回答
反對(duì) 回復(fù) 2023-09-15
  • 1 回答
  • 0 關(guān)注
  • 142 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)