javascript - angular ng-repeat的問題
問題描述
我本地寫了個json文件叫demo.js,然后我想ng-repeat里面的數據。現在遇到的問題是:我不知道怎么循環出roles的數據。
{ 'demoData': [{ 'dp': 'aaa1', 'name': '用戶名1', 'number': '11111', 'score': '22222', 'salary': '11111', 'jobs': 'scripts', 'roles': [{ 'new': 'bbb', 'edit': 'ddd', 'ccc': 'aaaa', 'del': 'dddd'} ], 'other': '備注', 'action': '刪除'},{ 'dp': 'bbb', 'name': '用戶名1', 'number': '11111', 'score': '22222', 'salary': '11111', 'jobs': 'scripts', 'roles': [{ 'new': 'bbb', 'edit': 'ddd', 'ccc': 'aaaa', 'del': 'dddd'} ], 'other': '備注', 'action': '刪除'} ]}
問題解答
回答1:<h1 ng-repeat='item in demoData[0].roles'>{{item}}</h1>回答2:
//如果是要在html里面用的話樓上的方法可以 //<h1 ng-repeat='item in demoData[0].roles'>{{item}}</h1> angular.forEach(demoData,function(data,index,array){angular.forEach(data.roles,function(role,index,array){ console.log(role);}) })回答3:
<p ng-repeat='(item,index) in demoData'> <p ng-repeat='item in demoData[index].roles'>{{item}} </p></p>回答4:
兩層嵌套即可解決
回答5:嵌套循環
<p ng-repeat='item in demoData'> <p ng-repeat='item2 in item.roles'>{{item2}} </p></p>
相關文章:
1. thinkPHP5中獲取數據庫數據后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙2. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?3. linux運維 - python遠程控制windows如何實現4. Python2中code.co_kwonlyargcount的等效寫法5. python - 如何對列表中的列表進行頻率統計?6. django - Python error: [Errno 99] Cannot assign requested address7. mysql數據庫做關聯一般用id還是用戶名8. javascript - 如何用最快的速度C#或Python開發一個桌面應用程序來訪問我的網站?9. python小白,關于函數問題10. python小白 關于類里面的方法獲取變量失敗的問題
