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. python - django 里自定義的 login 方法,如何使用 login_required()2. python如何不改動文件的情況下修改文件的 修改日期3. angular.js - Angular路由和express路由的組合使用問題4. angular.js - angularjs 用ng-reapt渲染的dom 怎么獲取上面的屬性5. mysql優化 - mysql count(id)查詢速度如何優化?6. 主從備份 - 跪求mysql 高可用主從方案7. css3 - [CSS] 動畫效果 3D翻轉bug8. angular.js - 不適用其他構建工具,怎么搭建angular1項目9. mysql主從 - 請教下mysql 主動-被動模式的雙主配置 和 主從配置在應用上有什么區別?10. node.js - node_moduls太多了
![css3 - [CSS] 動畫效果 3D翻轉bug](http://www.cgvv.com.cn/attached/image/news/202304/110831f073.png)