发布网友 发布时间:2022-04-21 14:17
共1个回答
热心网友 时间:2023-07-16 18:49
var data = [{"xvalue":"美国","yvalue":"方法","value":"42"},
{"xvalue":"美国","yvalue":"计算机","value":"92"},
{"xvalue":"山东","yvalue":"一种","value":"100"},
{"xvalue":"山东","yvalue":"系统","value":"94"},
{"xvalue":"山东","yvalue":"计算机","value":"177"},
{"xvalue":"上海","yvalue":"方法","value":"47"},
{"xvalue":"上海","yvalue":"的","value":"55"},
{"xvalue":"上海","yvalue":"装置","value":"35"}];
var x = ['美国','山东','上海'];
var y = ['方法','计算机','一种','系统','的','装置'];
var getV = function(yy, x, data){
var v = [];
for(var j=0;j<x.length;j++){
var xj = x[j], yes = 0;
for(var i =0;i<data.length;i++){
var di = data[i];
if(di.xvalue==xj && di.yvalue==yy){
v.push(di.value);
yes = 1;
break;
}
}
if(!yes){
v.push(0);
}
}
return v;
}
var yy = "方法";
var v = getV(yy, x, data);
console.log(v);
yy = "计算机";
v = getV(yy, x, data);
console.log(v);
追问关注大神你有段时间了,我很多对于数据的操作的问题大部分也都是你回答的,,,真是感谢你了