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 = { // 關(guān)鍵! 創(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)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue2+el-menu實現(xiàn)路由跳轉(zhuǎn)及當前項的設置方法實例
這篇文章主要介紹了vue2+el-menu實現(xiàn)路由跳轉(zhuǎn)及當前項的設置,方法實例代碼詳解,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-11-11
vue-router vuex-oidc動態(tài)路由實例及功能詳解
這篇文章主要為大家介紹了vue-router vuex-oidc動態(tài)路由實例及功能詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-11-11
使用vue3實現(xiàn)element-plus的主題切換效果
Vue3 Element Plus是一個基于Vue 3框架的UI組件庫,它是由Element UI團隊開發(fā)的升級版本,Element Plus延續(xù)了Element UI簡潔、高效的風格,并引入了一些新的設計語言和技術(shù),如響應式API和更好的性能優(yōu)化,本文給大家介紹了如何使用vue3實現(xiàn)element-plus的主題切換效果2024-12-12

