vue如何循環(huán)給對象賦值
循環(huán)給對象賦值
async submitForm() { var that = this that.allPersonList = [] // 出庫信息數(shù)組 // 循環(huán) 得到 A0000 for (var i = 0; i < that.personList.length; i++) {//循環(huán)拿到傳過來的對象集合 personList[{},{},.......] // 出庫信息 const newOut = { // 關鍵! 創(chuàng)建一個新對象 A0000: that.personList[i].a0000, // 將循環(huán)拿到的屬性循環(huán)賦值給newOut.A0000 AG8700: that.getUuid(), AG8701: this.outWareList[0], AG8702: this.outWare.AG8702 } that.allPersonList.push(newOut)// 循環(huán)賦值好的對象 push到 集合中 }
alert(JSON.stringify(that.allPersonList))---------> 打印的數(shù)據(jù)格式:
把已知數(shù)組循環(huán)賦值給另一數(shù)組
已知數(shù)組如下:
currentGood:[{name:'Da',ids:'aaa',pp:'123'},{name:'Cc',ids:'bbb',pp:'456'},{name:'Vv',ids:'ccc',pp:'789'}]
設置另一數(shù)組為modeDetail[]
? ? ? for (let i=0;i<this.currentGood.length;i++){ ? ? ? ? let modelItem={}; ? ? ? ? modelItem["id"]=this.currentGood[i].ids; ? ? ? ? modelItem["name"]=this.currentGood[i].name; ? ? ? ? modelItem["tele"]=this.currentGood[i].pp; ? ? ? ? modeDetail[i]=modelItem; ? ? ? } ? ? ? console.log(modeDetail);
運行調(diào)試結(jié)果如下
作用就是把已知的數(shù)據(jù),重新挑選
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
關于Vue中echarts響應式頁面變化resize()的用法介紹
Vue項目中開發(fā)數(shù)據(jù)大屏,使用echarts圖表根據(jù)不同尺寸的屏幕進行適配,resize()可以調(diào)用echarts中內(nèi)置的resize函數(shù)進行自適應縮放,本文將給大家詳細介紹resize()的用法,需要的朋友可以參考下2023-06-06在 vue-cli v3.0 中使用 SCSS/SASS的方法
關于如何在 vue-cli v3.0 中使用 SCSS/SASS,這里提供三種方案。感興趣的朋友通過本文一起學習吧2018-06-06vue中內(nèi)嵌iframe的src更新頁面未刷新問題及解決
這篇文章主要介紹了vue中內(nèi)嵌iframe的src更新頁面未刷新問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12