【发布时间】:2017-09-23 19:04:58
【问题描述】:
问题
我正在使用 Ionic 和 Firebase 来开发应用程序。
不知道为什么,只显示最后添加到数据库的数据。
我尝试使用“value”而不是“child_added”,但我得到了一个列表,其中只有原始值 {"data":"Hello"}
我想得到一个只有值的列表!
感谢您的帮助
news.html
<ion-view title="News">
<ion-nav-buttons side="right">
<button ng-click="messageCreator()" class="button button-icon ion-ios-chatboxes-outline"></button>
</ion-nav-buttons>
<ion-content class="has-header">
<ion-list ng-controller="displayMessages">
<ion-item ng-click="goCalendar()" ng-repeat="val in value" class="item item-icon-right">
{{val}}
<a class="icon icon-accessory ion-chevron-right"></a>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
新建数据的方法
$scope.messageCreator = function () {
$ionicPopup.prompt({
title: 'New message',
}).then(function(res) {
firebase.database().ref('ParentName').push().set({
data: res
}).then(function() {
alert("Data submitted");
}).catch(function(error) {
alert(error.message);
});
});
}
显示数据的方法
$scope.displayMessages = function ($timeout) {
var testRef = firebase.database().ref('ParentName');
testRef.on('child_added', function (snapshot) {
$timeout(function () {
update(snapshot);
});
});
function update (snapshot) {
$scope.value = snapshot.val();
}
}
仅显示最后添加到数据库的数据
【问题讨论】:
-
到列表...
标签: javascript firebase ionic-framework firebase-realtime-database