亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

大佬們遇到過這個問題嗎?js怎么遍歷給對象賦值

大佬們遇到過這個問題嗎?js怎么遍歷給對象賦值

慕森王 2019-10-25 23:14:40
這看起來有點繁瑣,可以簡化也行,新手,謝謝大佬,感謝getChartsData(this.rule).then(res=>{letobj=res.data.data[0];this.compRegion.lineCode=obj.lineCode;this.compRegion.lineCodeName=obj.lineCodeName;this.compRegion.timeRate=obj.timeRate;this.compRegion.performanceRate=obj.performanceRate;this.compRegion.percentRate=obj.percentRate;this.compRegion.deviceRate=obj.deviceRate;this.compRegion.deviceOee=obj.deviceOee;this.compRegion.deviceTeep=obj.deviceTeep;this.compRegion.startRate=obj.startRate;this.compRegion.planRate=obj.planRate;});
查看完整描述

2 回答

?
慕萊塢森

TA貢獻1810條經驗 獲得超4個贊

這樣?
getChartsData(this.rule).then(res=>{
letobj=res.data.data[0];
letneedKey=['lineCode','lineCodeName','timeRate','performanceRate','percentRate','deviceRate','deviceOee','deviceTeep','startRate','planRate']
needKey.forEach(item=>{
this.compRegion[item]=obj[item]
})
});
                            
查看完整回答
反對 回復 2019-10-25
?
一只甜甜圈

TA貢獻1836條經驗 獲得超5個贊

//解構
this.compRegion={...res.data.data[0]}
//如果還有一些多余的字段不想帶進去可以使用only這庫
importonlyform'only'
//前提this.compRegion有初始屬性
this.compRegion=only(res.data.data[0],Object.keys(this.compRegion))
                            
查看完整回答
反對 回復 2019-10-25
  • 2 回答
  • 0 關注
  • 283 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號