//立即执行
(function(l){
console.log(l)
})($)
//模块化
(function(l){
console.log(l)
}($))
//注意以上两者的区别
JavaScript处理数据:
pca.forEach((i)=>{finallist.push({code:i.provinceCode,name:i.provinceName,parentCode:null})})
pca.forEach((i)=>{i.mallCityList.forEach((j)=>{finallist.push({code:j.cityCode,name:j.cityName,parentCode:i.provinceCode})})})
pca.forEach((i)=>{i.mallCityList.forEach((j)=>{j.mallAreaList.forEach((k)=>{
finallist.push({code:k.areaCode,name:k.areaName,parentCode:j.cityCode})
})})})
//参考:https://blog.csdn.net/zhoudapeng01/article/details/101112682
var content = JSON.stringify(finallist);
var eleLink = document.createElement('a');
eleLink.download = "InterpretationLithology.json";
eleLink.style.display = 'none';
// 字符内容转变成blob地址
var blob = new Blob([content]);
eleLink.href = URL.createObjectURL(blob);
// 触发点击
document.body.appendChild(eleLink);
eleLink.click();
// 然后移除
document.body.removeChild(eleLink);
js写递归函数时,变量覆盖现象,递归函数的临时变量声明不可以省略var关键字:
findChildNode = function (node, lf){
if(!node) return;
if(node.length>0){ //数组
for(var i=0;i<node.length;i++){//这个地方的var不可省略
findChildNode(node[i],lf);
}
}else{
if(node && node.children && node.children.length>0){
for(var i=0;i<node.children.length;i++){//这个地方的var不可省略
findChildNode(node.children[i],lf);
}
}else{
lf.push(node)
}
}
}