Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取列的总数_Javascript_Html_Jquery - Fatal编程技术网

Javascript 获取列的总数

Javascript 获取列的总数,javascript,html,jquery,Javascript,Html,Jquery,我已经创建了带有json响应的表。我想得到列的和 const pipeline=[{Geo:“亚太地区”,salestage:“提案已提交”,计数:11,pipelinevalue:1}, {Geo:“NSU”,SalesStage:“提案已提交”,计数:4,管道值:2}, {Geo:“中东”,SalesStage:“提案已提交”,计数:17,管道价值:1}, {Geo:“美国东部”,SalesStage:“提案已提交”,计数:14,管道价值:1}, {Geo:“欧洲”,SalesStage:

我已经创建了带有json响应的表。我想得到列的和

const pipeline=[{Geo:“亚太地区”,salestage:“提案已提交”,计数:11,pipelinevalue:1},
{Geo:“NSU”,SalesStage:“提案已提交”,计数:4,管道值:2},
{Geo:“中东”,SalesStage:“提案已提交”,计数:17,管道价值:1},
{Geo:“美国东部”,SalesStage:“提案已提交”,计数:14,管道价值:1},
{Geo:“欧洲”,SalesStage:“提案已提交”,计数:9,管道价值:2},
{Geo:“美国西部”,SalesStage:“提案已提交”,计数:6,管道价值:1}];
genetateTable(管道“geo#u summary thead”、“geo#u summary tbody”、“pipeval='1');
函数genetateTable(管道、divHeader、divBody、pipeval){
$。每个(管道、功能(索引、项目){
const$tr=$('');
如果(pipeval='1'){
$tr.append([item.salestage,item.count,item.pipelinevalue].map(x=>$('').text(x));
}else{$tr.append([item.salestage,item.count].map(x=>$('').text(x));}
$(divBody)。追加($tr);
});
}

OpportunityTypeLineCountPipeline值
const管道=[{
Geo:“亚太地区”,
SalesStage:“已提交提案”,
计数:11,
管道值:1
},
{
地理:“NSU”,
SalesStage:“已提交提案”,
计数:4,
管道值:2
},
{
Geo:“中东”,
SalesStage:“已提交提案”,
计数:17,
管道值:1
},
{
Geo:“美国东部”,
SalesStage:“已提交提案”,
计数:14,
管道值:1
},
{
Geo:“欧洲”,
SalesStage:“已提交提案”,
计数:9,
管道值:2
},
{
Geo:“美国西部”,
SalesStage:“已提交提案”,
计数:6,
管道值:1
}
];
genetateTable(管道“geo#u summary thead”、“geo#u summary tbody”、“pipeval=”1“);
函数genetateTable(管道、divHeader、divBody、pipeval){
设totalCount=0;
设totalValue=0;
$。每个(管道、功能(索引、项目){
const$tr=$('');
totalCount+=item.count;
totalValue+=item.pipelinevalue;
如果(pipeval='1'){
$tr.append([item.salestage,item.count,item.pipelinevalue].map(x=>$('').text(x));
}否则{
$tr.append([item.salestage,item.count].map(x=>$('').text(x));
}
$(divBody)。追加($tr);
});
$('geo_summary')。追加($('Total${totalCount}${totalValue}'))
}

机会
管道计数
管道价值
const管道=[{
Geo:“亚太地区”,
SalesStage:“已提交提案”,
计数:11,
管道值:1
},
{
地理:“NSU”,
SalesStage:“已提交提案”,
计数:4,
管道值:2
},
{
Geo:“中东”,
SalesStage:“已提交提案”,
计数:17,
管道值:1
},
{
Geo:“美国东部”,
SalesStage:“已提交提案”,
计数:14,
管道值:1
},
{
Geo:“欧洲”,
SalesStage:“已提交提案”,
计数:9,
管道值:2
},
{
Geo:“美国西部”,
SalesStage:“已提交提案”,
计数:6,
管道值:1
}
];
genetateTable(管道“geo#u summary thead”、“geo#u summary tbody”、“pipeval=”1“);
函数genetateTable(管道、divHeader、divBody、pipeval){
设totalCount=0;
设totalValue=0;
$。每个(管道、功能(索引、项目){
const$tr=$('');
totalCount+=item.count;
totalValue+=item.pipelinevalue;
如果(pipeval='1'){
$tr.append([item.salestage,item.count,item.pipelinevalue].map(x=>$('').text(x));
}否则{
$tr.append([item.salestage,item.count].map(x=>$('').text(x));
}
$(divBody)。追加($tr);
});
$('geo_summary')。追加($('Total${totalCount}${totalValue}'))
}

机会
管道计数
管道价值

下面是一个没有jQuery的惯用解决方案:

const create=document.createElement.bind(文档);
const query=document.querySelector.bind(文档);
常量管道=[
{Geo:'APAC',SalesStage:'Proposal Submitted',计数:11,pipelinevalue:1},
{Geo:'NSU',SalesStage:'Proposal Submitted',计数:4,pipelinevalue:2},
{Geo:'Middle East',SalesStage:'Proposal Submitted',计数:17,pipelinevalue:1},
{Geo:'US East',SalesStage:'Proposal Submitted',计数:14,pipelinevalue:1},
{Geo:'Europe',SalesStage:'Proposal Submitted',计数:9,pipelinevalue:2},
{Geo:'US West',SalesStage:'Proposal Submitted',计数:6,管道值:1}
];
const totals=pipeline.reduce((totals,{count,pipelinevalue})=>{
总计.计数+=计数;
totals.value+=管道值;
返回总数;
},{count:0,value:0});
const table=查询('table');
const trTitles=创建('tr');
表.附加(标题);
['Opportunity','Pipeline Count','Pipeline Value'].forEach(title=>{
const th=创建('th');
trTitles.append(th);
th.textContent=标题;
});
pipeline.forEach(数据=>{
const tr=创建('tr');
表3.追加(tr);
Object.values(数据).slice(1).forEach(数据=>{
const td=创建('td');
tr.append(td);
td.textContent=基准;
});
});
const tfoot=create('tfoot');
表1.append(tfoot);
const trFoot=create('tr');
tfoot.append(trFoot);
常量{count,value}=总计;
['Total',count,value].forEach(条目=>{
const td=创建('td');
trFoot.append(td);
td.textContent=条目;
});
thead{
背景色:#00f;
颜色:#fff
}
th{
背景色:#66cdf2;
颜色:#000
}

下面是一个没有jQuery的惯用解决方案:

const create=document.createElement.bind(文档);
const query=document.querySelector.bind(文档);
常量管道=[
{Geo:'APAC',SalesStage:'Proposal Submitted',计数:11,pipelinevalue:1},
{Geo:'NSU',SalesStage:'提案