javascript - angular中controller里面雙層遍歷為何實(shí)現(xiàn)不了
問題描述
我需要實(shí)現(xiàn)這個(gè)功能,把獲得的數(shù)據(jù)進(jìn)行遍歷出一層,然后再對(duì)每一項(xiàng)遍歷,把每一項(xiàng)的數(shù)據(jù)的某個(gè)值賦予給上一層,但是卻實(shí)現(xiàn)不了。怎么辦?代碼: var datalist=[];
var dataDe = data.body.data.assets;for(var i = 0;i<dataDe.length;i++){ for(var j= 0;j<dataDe[i].userAssetList.length;j++){dataDe[i].userDtoName = dataDe[i].userAssetList[j];datalist.push(dataDe[i]); }}$scope.datalist=datalist; 事實(shí)證明第二個(gè)循環(huán)里面的值alert可以出來。但是賦值給外層的元素就不行了。怎么解決。求大神。 數(shù)據(jù)結(jié)構(gòu)如下:我是想把userassetlist里面的數(shù)組進(jìn)行遍歷然后賦值給上一層。'data': {'assets': [ {'id': '001','assetCount': 14,'availableCount': 9,'price': 2,'startDate': null,'age': 0,'description': '','assetType': '臺(tái)式機(jī)','assetName': '賽爾','assetModel': 'Z-01','userAssetList': [ {'userDTO': { 'confirmationDate': null, 'firstJobDate': null, 'id': '', 'userCount': 0, 'orgList': [], 'roleList': [], 'salaryTypeList': [], 'socialSecurityList': [], 'failCount': 0, 'name': '管理員', 'personalEmail': '932276768@qq.com', 'personalPhone': '', 'personalPhoneCountryCode': '86', 'lastSalary': 0, 'lastSalaryStartDate': null, 'currentSalary': 0, 'currentSalaryStartDate': null, 'birthDate': null, 'joiningDate': null, 'successCount': 0, 'locked': false, 'identified': true, 'active': false},'count': 3 }, {'userDTO': { 'confirmationDate': null, 'firstJobDate': null, 'id': '', 'userCount': 0, 'orgList': [], 'roleList': [], 'salaryTypeList': [], 'socialSecurityList': [], 'failCount': 0, 'name': '沙琪瑪', 'personalEmail': 'zdygx951@163.com', 'personalPhone': '17328121234', 'personalPhoneCountryCode': '86', 'lastSalary': 0, 'lastSalaryStartDate': null, 'currentSalary': 0, 'currentSalaryStartDate': null, 'birthDate': null, 'joiningDate': null, 'successCount': 0, 'locked': false, 'identified': true, 'active': false},'count': 2 }],
問題解答
回答1:為什么不可以呢,你的代碼,一行沒改:
var data = { 'assets': [ {'id': '001','assetCount': 14,'availableCount': 9,'price': 2,'startDate': null,'age': 0,'description': '','assetType': '臺(tái)式機(jī)','assetName': '賽爾','assetModel': 'Z-01','userAssetList': [{ 'userDTO': {'confirmationDate': null,'firstJobDate': null,'id': '','userCount': 0,'orgList': [],'roleList': [],'salaryTypeList': [],'socialSecurityList': [],'failCount': 0,'name': '管理員','personalEmail': '932276768@qq.com','personalPhone': '','personalPhoneCountryCode': '86','lastSalary': 0,'lastSalaryStartDate': null,'currentSalary': 0,'currentSalaryStartDate': null,'birthDate': null,'joiningDate': null,'successCount': 0,'locked': false,'identified': true,'active': false }, 'count': 3},{ 'userDTO': {'confirmationDate': null,'firstJobDate': null,'id': '','userCount': 0,'orgList': [],'roleList': [],'salaryTypeList': [],'socialSecurityList': [],'failCount': 0,'name': '沙琪瑪','personalEmail': 'zdygx951@163.com','personalPhone': '17328121234','personalPhoneCountryCode': '86','lastSalary': 0,'lastSalaryStartDate': null,'currentSalary': 0,'currentSalaryStartDate': null,'birthDate': null,'joiningDate': null,'successCount': 0,'locked': false,'identified': true,'active': false }, 'count': 2}] } ]}var datalist=[];var dataDe = data.assets;for(var i = 0;i<dataDe.length;i++){ for(var j= 0;j<dataDe[i].userAssetList.length;j++){dataDe[i].userDtoName = dataDe[i].userAssetList[j];datalist.push(dataDe[i]); }}
相關(guān)文章:
1. javascript - 這兩種函數(shù)寫法各有什么好處?2. 微信支付 - python做微信企業(yè)付款出現(xiàn)CA證書錯(cuò)誤3. 前端 - css3傾斜帶來問題部分?4. node.js - vue 子組件的菜單 如何與 父組件 通信?5. javascript - node環(huán)境使用vue-cli 配置代理6. 了解Java中的有限泛型。有什么意義?7. html5 - HTML代碼中的文字亂碼是怎么回事?8. html5 - 如何禁止百度轉(zhuǎn)碼?9. 網(wǎng)站在移動(dòng)的環(huán)境下手機(jī),pc打不開10. angular.js - vue or angular.2 or react
