我试图将Firebase快照的结果作为数组返回,以便我可以通过它们ng-repeat
(默认情况下,它返回对象)最后一行是我尝试设置的位置数组中的对象并将它们设置为重复范围。但我似乎对将值设置为数组的基本概念感到困惑:/任何帮助都很棒。将Firebase快照作为数组获取并设置为范围
const businessKey = '-KQ1hFH0qrvKSrymmn9d';
const rootRef = firebase.database().ref();
const discoverRef = rootRef.child('discover');
const businessRef = rootRef.child('businesses');
function getDiscoverBarContent(key, cb) {
discoverRef.child(key).on('child_added', snap => {
let businesRef = businessRef.child(snap.key);
businesRef.once('value', cb);
});
}
getDiscoverBarContent(businessKey, snap => {
snap.forEach((child) => {
var item = {};
item._key = snap.val();
array.push(item);
/*$scope.discover = array*/
})
});