V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
tonghuazhen
V2EX  ›  问与答

求解,封装 JSON

  •  
  •   tonghuazhen · 2018-05-22 19:05:56 +08:00 · 1016 次点击
    这是一个创建于 2165 天前的主题,其中的信息可能已经有所发展或是发生改变。
    for(let i in res.requestFields){
                var reqArr = [];
                var propObj ={};
                for(var a =0;a<$(".childrenProp").length;a++){
                    if($(".childrenProp").eq(a).attr("data-class") == res.requestFields[i].id){
                        propObj[$(".childrenProp").eq(a).attr("data-prop")]=$(".childrenProp").eq(a).val();
                        console.log(propObj)
                    }
                }
                reqArr.push(propObj);
                console.log(reqArr)
                ReqObj[res.requestFields[i].id]=reqArr;
            }
            console.log(ReqObj)
    

    求解,我这个 for 循环 json 添加数据被覆盖,该怎么写
    propObj[$(".childrenProp").eq(a).attr("data-prop")]=$(".childrenProp").eq(a).val();

    tonghuazhen
        1
    tonghuazhen  
    OP
       2018-05-22 19:06:51 +08:00
    ![微信截图_20180522190558.png]( https://i.loli.net/2018/05/22/5b03f9c22b8bf.png)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3244 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:25 · PVG 22:25 · LAX 07:25 · JFK 10:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.