【发布时间】:2013-12-16 07:40:21
【问题描述】:
我正在为 D&D 风格的 RPG 开发基于 Web 的角色创建工具。我正在尽最大努力从我的 firebase 数据库中列出“种族”。当前结构如下:
|-ironkingdoms
|--Race
|---Dwarf
|-----RaceName:Dwarf
|-----Starting Attribuites
|------PHY:7
|------STR:8
|------POI:5
|---Human
|-----RaceName:Human
|-----Starting Attributes
|------PHY:6
|------STR:7
|------POI:4
你明白了......我把“RaceName”放在那里,因为我一生都无法弄清楚如何让它列出“Race”的所有孩子。这是我的代码:
http://plnkr.co/edit/GhQn1e9bdCdAnKNsJZ1K?p=preview
<html ng-app="myapp">
<head>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js'></script>
<script src='https://cdn.firebase.com/v0/firebase.js'></script>
<script src='https://cdn.firebase.com/libs/angularfire/0.5.0/angularfire.min.js'></script>
</head>
<body ng-controller="MainCtrl">
Data:
<div ng-repeat="item in data">{{item.RaceName}}</div>
<p>
<div>Data loaded: {{dataLoaded}}</div>
<p>
Messages:
<div ng-repeat="msg in messages">{{msg}}</div>
<script>
var app = angular.module('myapp', ['firebase']);
app.controller('MainCtrl', function($scope, $firebase) {
var ref = new Firebase("https://<yourFirebase>.firebaseio.com/Race");
$scope.data = $firebase(ref);
$scope.dataLoaded = "Not yet!";
$scope.messages = [];
$scope.data.$on("loaded", function() {
var keys = $scope.data.$getIndex();
["Race"].forEach( function(element) {
$scope.messages.push("Test for " + element + ": " + (keys.indexOf(element) !== -1));
});
$scope.dataLoaded = "Yep!";
})
});
</script>
</body>
</html>
到目前为止,当我使用“RaceName”时,它似乎可以正常工作,但无论何时我将 /Race 从路径中移除并尝试列出“race”的孩子,它似乎都不起作用。我所掌握的少量数据库知识来自于 SQL 背景。所以这对我来说有点困惑。任何帮助,将不胜感激!
编辑: 在我的问题中添加更多内容。不确定它会得到回答,但我宁愿不为此提出一个新问题。
在以下情况下如何使用 ng-repeat:
<table>(Work in progress) Table with Rows of AttributeType with columns of AttributeGroup
<thead>
<tr>
<th>Attribute Set</th>
<th>Starting Attributes</th>
<th>Hero Limit</th>
<th>Veteran Limit</th>
<th>Epic Limit</th>
</tr>
</thead>
<tbody ng-model="refAttributes">
<tr>
<td>AGI</td>
<td>{{refAttributes['Starting Attributes'].AGI}}</td>
<td>{{refAttributes['Hero Limit'].AGI}}</td>
<td>{{refAttributes['Veteran Limit'].AGI}}</td>
<td>{{refAttributes['Epic Limit'].AGI}}</td>
</tr>
<tr>
<td>ARC</td>
<td>{{refAttributes['Starting Attributes'].ARC}}</td>
<td>{{refAttributes['Hero Limit'].ARC}}</td>
<td>{{refAttributes['Veteran Limit'].ARC}}</td>
<td>{{refAttributes['Epic Limit'].ARC}}</td>
</tr>
<tr>
<td>INT</td>
<td>{{refAttributes['Starting Attributes'].INT}}</td>
<td>{{refAttributes['Hero Limit'].INT}}</td>
<td>{{refAttributes['Veteran Limit'].INT}}</td>
<td>{{refAttributes['Epic Limit'].INT}}</td>
</tr>
<tr>
<td>PER</td>
<td>{{refAttributes['Starting Attributes'].PER}}</td>
<td>{{refAttributes['Hero Limit'].PER}}</td>
<td>{{refAttributes['Veteran Limit'].PER}}</td>
<td>{{refAttributes['Epic Limit'].PER}}</td>
</tr>
<tr>
<td>PHY</td>
<td>{{refAttributes['Starting Attributes'].PHY}}</td>
<td>{{refAttributes['Hero Limit'].PHY}}</td>
<td>{{refAttributes['Veteran Limit'].PHY}}</td>
<td>{{refAttributes['Epic Limit'].PHY}}</td>
</tr>
<tr>
<td>POI</td>
<td>{{refAttributes['Starting Attributes'].POI}}</td>
<td>{{refAttributes['Hero Limit'].POI}}</td>
<td>{{refAttributes['Veteran Limit'].POI}}</td>
<td>{{refAttributes['Epic Limit'].POI}}</td>
</tr>
<tr>
<td>PRW</td>
<td>{{refAttributes['Starting Attributes'].PRW}}</td>
<td>{{refAttributes['Hero Limit'].PRW}}</td>
<td>{{refAttributes['Veteran Limit'].PRW}}</td>
<td>{{refAttributes['Epic Limit'].PRW}}</td>
</tr>
<tr>
<td>SPD</td>
<td>{{refAttributes['Starting Attributes'].SPD}}</td>
<td>{{refAttributes['Hero Limit'].SPD}}</td>
<td>{{refAttributes['Veteran Limit'].SPD}}</td>
<td>{{refAttributes['Epic Limit'].SPD}}</td>
</tr>
<tr>
<td>STR</td>
<td>{{refAttributes['Starting Attributes'].STR}}</td>
<td>{{refAttributes['Hero Limit'].STR}}</td>
<td>{{refAttributes['Veteran Limit'].STR}}</td>
<td>{{refAttributes['Epic Limit'].STR}}</td>
</tr>
</tbody>
</table>
【问题讨论】:
标签: angularjs firebase angularfire