vue js 物件轉陣列

周家大小姐.發表於2019-08-29

 物件:

 webSetting: {
        //公共JS指令碼
        GlobalJs: {
          Code: "123",
          Id: "1",
          Value: "34234"
        },
        //全站開關
        SiteStatus: {
          Code: "",
          Id: "",
          Value: ""
        },
        //全站關閉原因
        SiteNote: {
          Code: "",
          Id: "",
          Value: ""
        },
        //預購活動開關
        ReserveStatus: {
          Code: "",
          Id: "",
          Value: ""
        },
        //預購截止時間
        ReserveDeadline: {
          Code: "",
          Id: "",
          Value: ""
        },
        //預購人數限制
        ReserveLimit: {
          Code: "",
          Id: "",
          Value: ""
        },
        //預購人數基數
        ReserveMinCount: {
          Code: "",
          Id: "",
          Value: ""
        },
        //加盟活動開關
        JoiningStatus: {
          Code: "",
          Id: "",
          Value: ""
        }
      },

轉陣列:

   let settingObj=this.webSetting;
     let settingArr = Object.keys(settingObj).map(key => {
            //console.log(key); //為每個鍵名
            console.log(settingObj);
            return settingObj[key];  //把每個物件返回出去生成一個新的陣列中相當於0:{id:1}
          });

相關文章