tonghuazhen
V2EX  ›  问与答

求解,封装 JSON

  •  
  •   tonghuazhen · May 22, 2018 · 1372 views
    This topic created in 2925 days ago, the information mentioned may be changed or developed.
    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
       May 22, 2018
    ![微信截图_20180522190558.png]( https://i.loli.net/2018/05/22/5b03f9c22b8bf.png)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5370 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 07:58 · PVG 15:58 · LAX 00:58 · JFK 03:58
    ♥ Do have faith in what you're doing.