tonghuazhen
V2EX  ›  问与答

求解,封装 JSON

  •  
  •   tonghuazhen · May 22, 2018 · 1410 views
    This topic created in 2956 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   ·   898 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 20:56 · PVG 04:56 · LAX 13:56 · JFK 16:56
    ♥ Do have faith in what you're doing.