JavaScript-用Firebase和Angular填充数据表
作者:互联网
我对Firebase和整个网络开发工作非常陌生.
我正在尝试用我的Firebase中的数据填充网站中的数据表.
This is the datatable in bootstrap
以下是app.js
var app = angular.module("aocgApp", ["firebase"]);
app.controller("dataController", ["$scope", "$firebaseArray",
function($scope, $firebaseArray) {
var national = new Firebase("https://aoconsultinggroup.firebaseio.com/National");
$scope.schools = $firebaseArray(national);
}]);
最后是html代码:
<div class="panel-body">
<div ng-app="aocgApp" ng-controller="dataController">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>School Name</th>
<th>SATs</th>
<th>GPA</th>
<th>Tuition</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="school in schools">
<td>{{ schools.name }}</td>
<td>{{ schools.sat24l }}</td>
<td>{{ schools.gpa }}</td>
<td>{{ schools.tuition }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
感谢你的帮助.
编辑:以下是数据结构
aoconsultinggroup
L Business
L CS
L Engineering
L National
L 0
L name
L SAT
L GPA
L tuition
L 1
L name
L SAT
L GPA
L tuition
L 2
L name
L SAT
L GPA
L tuition
L 3
L name
L SAT
L GPA
L tuition
解决方法:
您的模板中的变量名称有误,这是学校而不是国家/地区:
<tr ng-repeat="school in schools">
<td>{{ school.name }}</td>
<td>{{ school.sat24l }}</td>
<td>{{ school.gpa }}</td>
<td>{{ school.tuition }}</td>
</tr>
在您的控制器中,您不需要使用$loaded().下载数据后,$firebaseArray()将触发$digest循环.
您需要的是:
var national = new Firebase("<your-firebase-app>/National");
$scope.schools = $firebaseArray(national);
这就是使学校在模板中工作的原因. school变量来自控制器的$scope,并且school变量在模板中创建.
标签:angularfire,firebase,angularjs,html,javascript 来源: https://codeday.me/bug/20191119/2034561.html