用Firebase和Angular填充数据表
populating datatable with Firebase and Angular
我对Firebase和整个web开发技巧都很陌生。
我正在尝试用我的Firebase中的数据填充我的网站中的数据表。
这是引导中的数据表
以下是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
您的模板中有错误的变量名,它是schools
而不是national
:
<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 in schools
在模板中工作的原因。schools
变量来自控制器的$scope
,school
变量在模板中创建。
相关文章:
- 单击鼠标,用MySQL数据填充html表单输入字段
- 单击一个数据表,填充第二个数据表
- 为什么不是't ng表将数据从数组填充到表中
- 使用 JS 填充 HTML 表,数据顺序错误
- 使用 ajax 从 mysql 填充 jQuery 数据表
- 使用 php 发送 json 填充数据表
- 数据表将字段值关联到按钮,而 ajax 填充表
- 使用 JQuery 使用数据填充现有表
- JQuery - 在表单中填充数据的正确方法
- C# MVC 填充数据表中的下拉列表组
- 用Firebase和Angular填充数据表
- 使用两个ajax调用在两个html表中填充数据
- 正在关闭json数据填充的表
- 使用JSON URL数据动态填充HTML表
- 使用JQuery、Ajax和PHP将数据填充到表中
- 表没有被填充从Ajax调用使用数据表插件的jQuery
- Javascript数据表填充数据问题(没有返回错误)
- SAPUI5从XMII填充数据表
- 使用JavaScript和JSON自动填充数据表
- 搜索后重新填充数据表网格的示例