如何使一个节点引用数据库Firebase中的另一个节点

如何使一个节点引用数据库Firebase中的另一个节点,firebase,firebase-realtime-database,Firebase,Firebase Realtime Database,我想创建两个节点 包含特定城市的节点区域 属于特定区域的节点城市 通常在SQL中,我们创建带有id\u region(主键)、name\u region的表区域,并创建带有id\u cities(主键)、name\u cities、id\u region的表城市,因此,我们引用带有id的区域表 我怎样才能在firebase数据库上打上点呢?这应该适合你 root: { cities: { $city_1: { region: $region_1 },

我想创建两个节点

  • 包含特定城市的节点区域
  • 属于特定区域的节点城市
通常在SQL中,我们创建带有
id\u region(主键)、name\u region
的表区域,并创建带有
id\u cities(主键)、name\u cities、id\u region
的表城市,因此,我们引用带有id的区域表


我怎样才能在firebase数据库上打上点呢?

这应该适合你

root: {
  cities: {
    $city_1: {
      region: $region_1
    },
    $city_2: {
      region: $region_1
    }
  },
  regions: {
    $region_1: {
      cities: {
        $city_1: true,  // This node can have any value really just as long as the key refers to $city_1
        $city_2: true   // Same
      }
    }
  }
}

这应该对你有用

root: {
  cities: {
    $city_1: {
      region: $region_1
    },
    $city_2: {
      region: $region_1
    }
  },
  regions: {
    $region_1: {
      cities: {
        $city_1: true,  // This node can have any value really just as long as the key refers to $city_1
        $city_2: true   // Same
      }
    }
  }
}

让我试试,我将用区域填充喷丝头1,用城市填充喷丝头2。是的,它是有效的。关于更多的解释,我参考[Category:创建可缩放的数据。让我试试,我将用区域填充spinner1,用城市填充spinner2。是的,它可以工作。有关更多的解释,我参考[Category:创建可缩放的数据。