設的列表呈遞每個孩子的信息說,有是在不同schools
類(groups
)的students
一些數據:在非規範化的數據結構
{
"students": {
"alexa" : {
"firstName" : "ReJina",
"grade" : 2,
"lastName" : "idk",
...
},
"bobby" : { ... },
"chris" : { ... },
...
},
"schools": {
"springfield" : {
"name" : "Springfield Elementary",
"location" : "123 Main St",
...
},
"quahog" : { ... },
"zion" : { ... },
...
},
"group": {
"one" : {
"members" : {
"alexa" : true,
"bobby" : true,
"chris" : true
},
"school" : {
"springfield" : true
},
"name" : "Math Class"
},
"two" : {
"members" : {
"bart" : true,
"lisa" : true,
"meg" : true,
...
},
"school" : {
"quahog" : true
},
"name" : "Art Class"
},
"three" : { ... },
"four" : { ... },
...
}
}
據我所知,這是正確的方式以平坦的方式構建數據。請讓我知道如果這是不正確的。我保留每個項目的相關名單,所以每個班級都需要一個名冊(members
),如果我也有學生在一個以上班級(group
)或學校的情況,那麼他們需要他們參加的班級和學校名單。
現在我們需要顯示所有的學校類(groups
),學生在每個班級和學生在同一視圖與嵌套ng-repeat
視圖中的HTML
:
<div id="data-table-div" class="col-md-6">
// Get all the groups, and show them one by one
<div ng-repeat="group in groups">
// This works - How do I get the school it is associated to?
// ??
{{group.name}} - {{group's school's name}}
//Start a table
<table>
<thead> <tr> <th>Student Name</th> <th>Grade</th> ... </thead>
<tbody>
// Get the students in each group, and show them one by one
// ??
<tr ng-repeat="student in groups.members">
<td>{{student.name}}</td> <td>{{student.grade}}</td> ...
</tr>
</tbody>
</table>
</div>
</div>
而且控制器:
angular.module('sofDataViewerApp')
.controller('dataTableController', function ($scope, $firebaseObject, $firebaseArray) {
// This gets all of our groups. It also allows `group.memebers` to render the appropriate number of `<tr>`s as it knows it has N students.
var groupsRef = new Firebase("https://sof-data.firebaseio.com/studyGroups");
$scope.groups = $firebaseArray(groupsRef);
// This will give all the students. How do I get just the template's `group.members` to be each appropriate student?
var studentsRef = new Firebase("https://sof-data.firebaseio.com/students");
$scope.allStudents = $firebaseArray(studentsRef);
});
問題:
如何獲得HTML模板適當地迭代OV呃groups
'members
我可以訪問每個student
的所有數據(例如他們的firstName
和grade
)? (我假設它可能涉及到控制器,並可能在HTML更好的代碼)
PLNKR:http://plnkr.co/edit/uAn1Ky9v5NHHDFPs2c6S?p=preview (如果你知道如何在plnkr注入火力地堡和angularFire,那麼它應該工作,但我仍然可以」 W圖表示出來,儘管其中包含的CDN ...)
我可以理解最接近的解釋是this page由火力地堡,他們建議使用LINK_ID
,但它沒有被描述爲他們的意思,尤其因爲他們聊關於不按id搜索。在我的情況下,link
將與group
同義,而comment
將是student
。
var commentsRef = new Firebase("https://awesome.firebaseio-demo.com/comments");
var linkRef = new Firebase("https://awesome.firebaseio-demo.com/links");
var linkCommentsRef = linkRef.child(LINK_ID).child("comments");
linkCommentsRef.on("child_added", function(snap) {
commentsRef.child(snap.key()).once("value", function() {
// Render the comment on the link page.
});
});