javascript - angular ng-repeat的問題
問題描述
我本地寫了個(gè)json文件叫demo.js,然后我想ng-repeat里面的數(shù)據(jù)。現(xiàn)在遇到的問題是:我不知道怎么循環(huán)出roles的數(shù)據(jù)。
{ '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:嵌套循環(huán)
<p ng-repeat='item in demoData'> <p ng-repeat='item2 in item.roles'>{{item2}} </p></p>
相關(guān)文章:
1. 數(shù)組按鍵值封裝!2. docker不顯示端口映射呢?3. java - 阿里的開發(fā)手冊中為什么禁用map來作為查詢的接受類?4. javascript - 使用vue官方腳手架進(jìn)行單元測試,如何覆蓋到watch里的變量?5. javascript - 為什么創(chuàng)建多行多列的表格最后只有一行內(nèi)有表格6. 如何用Java向kafka發(fā)送json數(shù)據(jù)7. javascript - webpack中alias配置中的“@”是什么意思?8. clone - git sourceTree克隆倉庫時(shí),都不停彈出Password Required彈窗,即時(shí)輸入正確的git賬號(hào)密碼還是彈出9. 主題切換問題,用過別人的webapp在后臺(tái)切換模板主題后手機(jī)端打開網(wǎng)頁就是切換到的主題了10. html5 - 使用echarts中的圖表 一個(gè)頁面導(dǎo)入了好幾個(gè)js圖表 實(shí)現(xiàn)echarts圖表隨著瀏覽器窗口變化而變化時(shí)出現(xiàn)了問題
