访问嵌套的firebase值

时间:2016-07-13 08:03:58

标签: ios swift firebase firebase-realtime-database

如果我有类似

的话
@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            x1 = event.getX();
            break;
        case MotionEvent.ACTION_UP:
            x2 = event.getX();
            float deltaX = x2 - x1;

            if (Math.abs(deltaX) > MIN_DISTANCE) {
                // Left to Right swipe action
                if (x2 > x1) {
                    Toast.makeText(this, "Left to Right swipe [Next]", Toast.LENGTH_SHORT).show();
                }

                // Right to left swipe action
                else {
                    Toast.makeText(this, "Right to Left swipe [Previous]", Toast.LENGTH_SHORT).show();
                }

            } else {
                // consider as something else - a screen tap for example
            }
            break;
    }
    return super.onTouchEvent(event);
}

你可以使用.Value的观察者并打印snapshot.value来获取所有内容。

但如果我有类似

的话
Person
   9283094823904
        username: bob
        password : wat

为什么如果我可以访问此人的UID并执行类似

的引用
Person
       092830948290384
           username: Bob
           password: wat
           favoriteColors
                  blue: "true"
                  green: "true"

该值返回null?

refPerson.child(092830948290384).child("favoriteColors").observeEventType(.Value)bhalbhlahb

print(snapshot) returns Snap (favoriteColors) <null>

我不明白为什么如果我有直接路线到favoriteColors的原因.Value的工作方式与一层备份的工作方式相同。

我知道建议是防止这种嵌套,但是没有办法让这种方法有效吗?

提前致谢。

1 个答案:

答案 0 :(得分:1)

尝试收听

refPerson.child(092830948290384).observeEventType(.Value)

并使用:

snapshot.value!["favoriteColors"] 

将您需要的数据输入字典

相关问题