javascript - angular中controller里面雙層遍歷為何實現(xiàn)不了
問題描述
我需要實現(xiàn)這個功能,把獲得的數(shù)據(jù)進(jìn)行遍歷出一層,然后再對每一項遍歷,把每一項的數(shù)據(jù)的某個值賦予給上一層,但是卻實現(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; 事實證明第二個循環(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': '臺式機(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': '臺式機(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. java固定鍵值轉(zhuǎn)換,使用枚舉實現(xiàn)字典?2. javascript - 移動端開發(fā) H5 頁面在 iOS手機(jī)上無法實現(xiàn) 長按復(fù)制文本 求解決3. 如何解決tp6在zend中無代碼提示4. java - HTTPS雙向認(rèn)證基礎(chǔ)上有無必要再進(jìn)行加簽驗簽?5. vim - win10無法打開markdown編輯器6. html - 如何使用用戶輸入的數(shù)據(jù)去運(yùn)行一個數(shù)學(xué)公式,最后怎么返回。7. python - flask學(xué)習(xí),user_syy添加報role is invalid keyword for User.8. 這是什么情況???9. css3 - less或者scss 顏色計算的知識應(yīng)該怎么學(xué)?或者在哪里學(xué)?10. javascript - 有沒有類似高鐵管家的時間選擇插件
