Javascript将数据放入列表

时间:2019-03-19 09:10:03

标签: javascript jquery mysql laravel

我有一个表,我想将从ajax调用中获得的数据以行而不是行的形式放入表中,这是表主体代码

<tbody id="tableData-marketMonth">
    <tr>
        <th>Leads</th>
    </tr>
    <tr>
        <th>Full Year Cost</th>
    </tr>
    <tr>
        <th>{{date('F')}} Share of Cost</th>
    </tr>
    <tr>
        <th>Cost per Lead</th>
    </tr>
</tbody>

这是将数据放入表中的JavaScript代码

//Monthly Marketing Cost Report
$.get('/dashboard/costs', function(data){
  $.each(data,function(i,value){
    var tr =$("<tr/>");

    tr.append($("<th/>",{
      text : value.olxTotal
    })).append($("<th/>",{
      text : value.budget_total_year
    })).append($("<th/>",{
      text : value.budget_total_month
    })).append($("<th/>",{
      text : value.budget_per_lead
    }))
    $('#tableData-marketMonth').append(tr);
  })  
})

这是当前输出 Current   所需的输出   Desired

非常感谢

1 个答案:

答案 0 :(得分:1)

我想我理解您的意思,可能最好只是将id添加到每个/** * Check if the block has content * * @param string $name * @param array $args Optional. Additional arguments, see get_the_block for more information */ function has_block( $name, $args = array() ) { if( 0 < strlen( get_the_block( $name, $args ) ) ) return true; return false; } 中,然后将值附加到它们上,如下所示。

HTML

<tr>

jQuery

<table>
    <tbody id="tableData-marketMonth">
        <tr id="leads">
            <th>Leads</th>
         </tr>
         <tr id="fyc">
             <th>Full Year Cost</th>
         </tr>
         <tr id="soc">
             <th>{{date('F')}} Share of Cost</th>
         </tr>
         <tr id="cpl">
             <th>Cost per Lead</th>
         </tr>
    </tbody>
</table>
相关问题