json 叠加 拼接 相同的 叠加 不相同 拼接

原创 李仁伟前端笔记 随笔 js 128阅读 2018-07-15 12:13:30 举报

<!DOCTYPE html>
<html>
<html>

<head>

<title>height</title>

<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" id="viewport" name="viewport">
<style type="text/css">

li{
display:inline-block;
border:1px solid #ccc;
}
.moveHide{
visibility:hidden;
}
.font i{
display: inline-block;
transform:scale(0.4,0.5);
}
</style>
</head>
<body>

<script src="jquery-3.3.1.min.js"></script>
<script>

var uId = 1234;
var allList=[{pId:"1",playId:"112",inum:1,num:1,qiNo:81,style:1},{pId:"1",playId:"112",inum:3,num:2,qiNo:81,style:1}];

var nowList=[{pId:"1",playId:"112",inum:1,num:3,qiNo:81,style:1},{pId:"1",playId:"112",inum:4,num:3,qiNo:81,style:1}];

//nowList.each();

nowList.map((item, index) => { //遍历 本次 数组 新数组
let qinNo = item["qiNo"];
let playId = item["playId"];
let inum = item["inum"];
let num2 = item["num"];
let icur = 0; //长度 参数
let find =false;

  allList.map((item2, index) => { //遍历老数组  重叠的 进行合并
    let obj = 0;
    icur++;
    // let objnum = null;
    if (item2["qiNo"] == `${qinNo}` && item2["playId"] == `${playId}` && item2["inum"] == `${inum}`) {
      //console.log(item2["num"],parseInt(num2),'0097');
      // item2["num"] = parseInt(item2["num"])+parseInt(num2);
      // objnum = parseInt(item2["num"]);
                // obj = 1;//console.log(item2["num"],parseInt(num2),'0097');
                item2['num'] = parseInt(item2["num"])+parseInt(num2);
                find = true;
                //break;
            }
            // else {
    //   if (icur == allList.length && obj == 0) {
    //     let obj = '{pId:' + item["pId"] + ',playId:' + item["playId"] + ',inum:' + item["inum"] + ',num:' + item["num"] + ',qiNo:' + item["qiNo"] + ',style:1' + '}';
    //     obj = eval("(" + obj + ")");
    //     objnum = item["num"];
    //     //allList.push(obj);
    //   }
    // }//除了 相等的 都是 不相等的 
    // if(objnum!=null){
    //   console.log(objnum,item2["playId"],item2["inum"],09);
    //   item2["num"] = parseInt(objnum);
    // }

        });

        if(!find) {
            allList.push(item);
        }

    });

    allList = JSON.stringify(allList);
    console.log(allList,'uu');
let allstr = 'allList'+uId;
localStorage.setItem(allstr, allList);

//console.log(obj,colors);
// removed = colors.splice(1, 1, "red", "purple"); //从位置1 删除一项,插入两项
// console.log("colors:" + colors); //green, red, purple, orange, blue
// console.log("return:" + removed); //yellow,返回的数组中只包含一项
</script>
</body>

</html>

评论 ( 0 )
最新评论
暂无评论

赶紧努力消灭 0 回复