遍历多重数组 形成表格 表头和表内容,去逗号,保留两位小数

 
  
$(function(){
    //移动弹出层
    $(".move").draggable();
    $('#marketData_show_close').click(function(){
        $('#marketData_show_tbody').html(' ');
        $('#marketData_show').hide();
    })
    $('.market_more').click(function(){
        $('#market_more_table tbody').html('');
        $('#marketData_show').show();
        var moreBtn = $(this).attr("date");
        var marktet_tbody = ' ';
        var data_tbody = " ";

        $.ajax({
            type:"GET",
            url:"/MarketData/detail",
            data:{ date:moreBtn},
            dataType:"json",
            success:function(data){
                var date = data.date;
                var data = data.list;
           /*     var add_installs = 0;
                var add_spent = 0;*/
                $.each(data,function(channel,val){
                    let marktet_tbody_header=" ";
                    let marktet_tbody=" ";
                    let data_channel = channel ;
                    let add_installs=0;
                    let add_spent=0;
                    marktet_tbody_header += ""
                        +""+date+""
                        +""+data_channel+""
                        +""+"  "+""
                        +"游戏"+""
                        +""
                        +""
                        +""
                        +"";
                    $.each(val,function(index,gamedata){
                        /*ÓÎÏ·idÄÚ²ã*/
                        marktet_tbody += ""
                            +""+date+""
                            +""+data_channel+""
                            +""+gamedata.language+""
                            +""+gamedata.gname+"["+gamedata.gid+"]"+""
                            +""+gamedata.installs+""
                            +""+gamedata.CPI+""
                            +""+gamedata.spent+""
                            +"";
                    /*  转化为整数,并去千位数逗号*/
                        add_installs+=parseInt((gamedata.installs.replace(",","")));//数据相加
                        add_spent+=parseInt((gamedata.spent.replace(",","")));//数据相加
                    })
                    $('#market_more_table tbody').append(marktet_tbody_header);
                    $('#market_more_table tbody').append(marktet_tbody);
                    $("#"+data_channel+"_install").text(add_installs);
			
 			/* 保留两位小数*/
$("#"+data_channel+"_spent").text(add_spent.toFixed(2)); $("#"+data_channel+"_cpi").text((add_spent/add_installs).toFixed(2)); }) }, error:function(){ alert("请求数据发生错误") } }) })})
 
  

 
  
 
 

你可能感兴趣的:(功能实现)