为什么在运行Android Studio时数组会空?

发布于 2025-02-13 02:31:45 字数 2030 浏览 0 评论 0原文

我正在使用React Native和Firebase实时数据库来存储和查询属性列表。看来,当我在iOS XCode中运行以下查询时,此处创建的数组会显示属性对象的列表。但是,当我运行这个Android Studio时,阵列为空。您知道可能导致这一点吗?有人可以在这里提供帮助,我是新手反应本地并使用firebase实时数据库的新手吗?

对于差的代码格式,我真的很抱歉:

const array = []

await db.ref(`users/`).on(`value`, snapshot => {
          if (snapshot.exists()) {
            snapshot.forEach(function(userSnapshot){
                if(userSnapshot.hasChild("properties")){
                    userSnapshot.child("properties").forEach((propertySnapshot) => {
                        array.push({
                          key: userSnapshot.key,
                          property: propertySnapshot.val(),
                          username: userSnapshot.val().username,
                          email: userSnapshot.val().email,
                          phoneNumber: (userSnapshot.val().phoneNumber != null)?userSnapshot.val().phoneNumber:null,
                          propertyName: propertySnapshot.key,
                          profile_pic: userSnapshot.val().profile_pic,
                          connectedAccount_id: (userSnapshot.val().connectedAccount_id != null)?userSnapshot.val().connectedAccount_id:null,
                          customer: (userSnapshot.val().customer != null)?userSnapshot.val().customer:null,
                        });
                    })
                }
            })
          }
        });

   await database().ref(`users/${auth().currentUser.uid}/your_location`).once(`value`, function(snap){
    ....

    Geocoder.init("******");
        
        Geocoder.from(locationPostcode)
            .then(json => {

              var location = json.results[0].geometry.location;

                global.latitude = location.lat;
                global.longtitude = location.lng;
            })
            .catch(error => console.warn(error));


         console.log("array result "+array)

    .....


     })

日志阵列显示了iOS的一系列对象: 阵列结果[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],

但对于Android,它是空的:

array结果

I am using react native and firebase realtime database to store and query a list of properties. It seems that when I run the below query in XCode for iOS the array created here shows a list of the property objects. However, when I run this android studio the array is empty. Do you know what may be causing this? Can someone please help here I am very new to react native and using firebase realtime database?

I really do apologies for the poor code formatting:

const array = []

await db.ref(`users/`).on(`value`, snapshot => {
          if (snapshot.exists()) {
            snapshot.forEach(function(userSnapshot){
                if(userSnapshot.hasChild("properties")){
                    userSnapshot.child("properties").forEach((propertySnapshot) => {
                        array.push({
                          key: userSnapshot.key,
                          property: propertySnapshot.val(),
                          username: userSnapshot.val().username,
                          email: userSnapshot.val().email,
                          phoneNumber: (userSnapshot.val().phoneNumber != null)?userSnapshot.val().phoneNumber:null,
                          propertyName: propertySnapshot.key,
                          profile_pic: userSnapshot.val().profile_pic,
                          connectedAccount_id: (userSnapshot.val().connectedAccount_id != null)?userSnapshot.val().connectedAccount_id:null,
                          customer: (userSnapshot.val().customer != null)?userSnapshot.val().customer:null,
                        });
                    })
                }
            })
          }
        });

   await database().ref(`users/${auth().currentUser.uid}/your_location`).once(`value`, function(snap){
    ....

    Geocoder.init("******");
        
        Geocoder.from(locationPostcode)
            .then(json => {

              var location = json.results[0].geometry.location;

                global.latitude = location.lat;
                global.longtitude = location.lng;
            })
            .catch(error => console.warn(error));


         console.log("array result "+array)

    .....


     })

The log array shows an array of objects for iOS:
array result [object Object],[object Object],[object Object],[object Object],[object Object]

but for android it's empty:

array result

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文