gpt4 book ai didi

javascript - 如何显示创建的数据?

转载 作者:行者123 更新时间:2023-11-29 14:44:36 24 4
gpt4 key购买 nike

我正在发送数据......

....
// upload on file select or drop
$scope.upload = function (file, id) {
id = typeof id !== 'undefined' ? id : null;
Upload.base64DataUrl(file).then(function(base64){
//auth
var fbAuth = FirebaseURL.getAuth();
//Ref
var ref = FirebaseURL.child("users_photos");
ref.push({'image': base64,'removed': true, 'user_id': fbAuth.uid, 'dt_created':Firebase.ServerValue.TIMESTAMP ,'dt_updated':Firebase.ServerValue.TIMESTAMP}, function(error){
if (error) {
alert('Error');
} else {
var newID = ref.key();

//I would like display data insert here?
console.log(DATA RESULT INSERT);
}
});
});

我想插入显示数据。

是否可以不用key查询就显示最后插入的对象?

最佳答案

Use AngularFire for synchronized collections.

使用 limitToLast(1) 创建查询以始终同步最后插入的对象。

angular.module('app', ['firebase'])
.constant('FirebaseUrl', '<my-firebase-app>')
.service('rootRef', ['FirebaseUrl', Firebase)
.factory('userItems', UserItems)
.controller('MyCtrl', MyController);

function UserItems($firebaseArray, rootRef) {
return function userItems(uid) {
var itemRef = rootRef.child('items');
var query = itemRef.orderyByChild('uid').equalTo(uid);
return $firebaseArray(query);
}
}

function MyController($scope, userItems, rootRef) {
$scope.items = userItems(rootRef.getAuth().uid);
$scope.addItem = function addItem(item) {
$scope.items.$add(item).then(function(ref) {
var record = $scope.items.$getRecord(ref.key());
// save the data to the other structure
});
};
}

See the section on Complex queries for more info.

关于javascript - 如何显示创建的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34334963/

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