javascript - angular ng-repeat的問題
問題描述
我本地寫了個json文件叫demo.js,然后我想ng-repeat里面的數據?,F在遇到的問題是:我不知道怎么循環出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. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?2. 學html時,點“運行實例”點“提交”,右邊的白框框沒任何反應。3. javascript - vue組件通過eventBus通信時,報錯a.$on is not a function4. javascript - web端請求一個正在被修改的文件會怎么樣?5. javascript - 自執行函數是當加載到這個js就執行函數了嗎6. javascript - js的shift()方法失效?7. javascript - react,獲取radio的值出錯8. javascript - 怎么實現讓 div 里面的 img 元素 中心居中, 如下示例圖9. javascript - IOS微信audio標簽不能通過touchend播放10. docker不顯示端口映射呢?
