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

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

通過ajax將數據附加到表中

通過ajax將數據附加到表中

嗶嗶one 2022-01-20 18:52:02
我在將數據附加到表體時遇到問題。代碼$.ajax({  type:'GET',  url:'{{url('dashboard/customer-groups')}}/'+ordID,  success:function(data){    console.log(data);  //screenshot below  }});截屏上面的 ajax 代碼返回的數據分為 2 個類別(組和客戶)HTML<table id="data-table" class="table table-striped table-bordered">    <thead>    <tr>        <th>#</th>        <th>Name</th> // from customers array        <th>Company</th> // from customers array        <th>Province</th> // from customers array        <th>City</th> // from customers array        <th>Email</th> // from customers array        <th>Industry</th> // from customers array        <th>Group</th> // from group    </tr>    </thead>    <tbody id="table_customer"></tbody></table>任何的想法?
查看完整描述

2 回答

?
慕沐林林

TA貢獻2016條經驗 獲得超9個贊

.each()您可以使用on success遍歷響應數據并將它們附加到表主體中。


演示:


let  data = {customers: [

  {id: 1, name:'John', group_id: 111, industry_id: 'xyz', company: 'abc', province: 'aaa', city: 'vv', email: 'aa@gmail.com'},

  {id: 2, name:'Kate', group_id: 222, industry_id: 'lmn', company: 'abc2', province: 'bbb', city: 'qq', email: 'zz@gmail.com'}

]};


$(data.customers).each(function(_, i){

  var row = `<tr><td></td><td>${i.name}</td><td>${i.company}</td><td>${i.province}</td><td>${i.city}</td><td>${i.email}</td><td>${i.industry_id}</td><td>${i.group_id}</td></tr>`;

  $('#table_customer').append(row);

});

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

<table id="data-table" class="table table-striped table-bordered">

    <thead>

    <tr>

        <th>#</th>

        <th>Name</th> 

        <th>Company</th>

        <th>Province</th>

        <th>City</th>

        <th>Email</th> 

        <th>Industry</th> 

        <th>Group</th> 

    </tr>

    </thead>

    <tbody id="table_customer"></tbody>

</table>


查看完整回答
反對 回復 2022-01-20
?
慕森王

TA貢獻1777條經驗 獲得超3個贊

    $.ajax({

      type:'GET',

      url:'{{url('dashboard/customer-groups')}}/'+ordID,

      success:function(data){

        const tr = $('tr');

        for (var key in data) {

           var obj = data[key];

           var id = "<td>"+obj.id+"</td>";

var group_id = "<td>"+obj.group_id+"</td>";



     // add more columns for other attributes

           var allTds = id+group_id;

         }

        tr.append(allTds);

       $('#data-table').append(tr);

      }

    });


查看完整回答
反對 回復 2022-01-20
  • 2 回答
  • 0 關注
  • 255 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號

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