gpt4 book ai didi

angularjs - 使用 Angularfire 列出来自 Firebase 的内容的更有效方法?

转载 作者:行者123 更新时间:2023-12-04 23:07:43 25 4
gpt4 key购买 nike

我正在为 D&D 风格的 Angular 色扮演游戏开发一个基于网络的 Angular 色创建工具。我正在尽最大努力从我的 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”的所有 child 。这是我的代码:

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”的子级时它似乎不起作用。我所拥有的一点 DB 知识来自 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>

最佳答案

第9行应该变成

<div ng-repeat="(raceName, item) in data">{{raceName}}</div>

ngRepeat 指令支持通过上述方式获取键和值。

关于angularjs - 使用 Angularfire 列出来自 Firebase 的内容的更有效方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20605656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com