火力地堡循环查找数据 [英] Firebase loop look up data
问题描述
$scope.authorizedUsers = [];
fbRef.child('folders/').child($routeParams.folderID).once('value',
function(ss) {
ss.forEach(function(childSnapshot) {
fbRef.child('users/').child(childSnapshot.name()).once('value',
function(user) {
$scope.authorizedUsers.push(user.val());
console.log($scope.authorizedUsers);
});
});
});
我用上面code。使用查找主数据然后循环他们认为 NG-重复
< DIV NG重复=用户authorizedUsers> {{}用户}< / DIV>
但是有时候只有环形数据显示。有时意味着我必须刷新几次,以获得数据显示。
but the looped data display sometimes only. Sometime means I have to refresh several time to get the data display.
任何想法或者有其他更好的方法来查找火力主数据?
Any idea or there is other better way to look up master data in firebase?
推荐答案
的回调异步调用的,所以他们没有角的消化范围内发生。因此,它们不会被施加到页面,直到一个新的编译发生
The callbacks are invoked asynchronously, so they don't happen within Angular's digest scope. Thus, they are not going to be applied to the page until a new compile occurs.
这 angularFire 内部使用的解决方法是调用$超时(),这将迫使角的编译过程中运行。有些实验将揭示的最有效的方式来完成这件事。这里有一个蛮力:
The solution that angularFire uses internally is to call $timeout(), which will force Angular's compile process to run. Some experimentation would reveal the most efficient way to get this done. Here's a brute force:
$scope.authorizedUsers = [];
fbRef.child('folders/').child($routeParams.folderID).once('value',
function(ss) {
ss.forEach(function(childSnapshot) {
fbRef.child('users/').child(childSnapshot.name()).once('value',
function(user) {
$timeout(function() {
$scope.authorizedUsers.push(user.val());
console.log($scope.authorizedUsers);
});
});
});
});
这篇关于火力地堡循环查找数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!