2016-08-01 98 views
2

我想爲一個顯示公司列表的應用程序構建適當的結構。當我點擊一家公司時,該應用會在其他視圖中顯示電話號碼。有人可以用我的結構來提醒我嗎?我的Firebase數據庫結構。這是正確的層次?

{ 
    "companies" : { 
    "c1" : { 
     "name" : "Secure Home LLP", 
     "subject" : "Security" 
    } 
    }, 
    "phones" : { 
    "c1" : { 
     "p1" : { 
     "name" : "Check point", 
     "phone" : "201-478-4600" 
     }, 
     "p2" : { 
     "name" : "Dispatcher", 
     "phone" : "201-478-4678" 
     } 
    } 
    } 
} 

My structure

回答

-1

你給將是一個偉大的工作勞累,而解析成不同的數據結構。

以下結構將是一個更好的選項。只需進入公司密鑰即可解析電話號碼。這裏是c1, c1

{ 
    "companies" : { 
    "c1" : { 
     "name" : "Secure Home LLP", 
     "subject" : "Security", 
     "p1" : { 
      "name" : "Check point", 
      "phone" : "201-478-4600" 
      }, 
     }, 
    "c2" : { 
     "name": "neCompanyName", 
     "subject" : "Design", 
     "p2" : { 
      "name" : "Dispatcher", 
      "phone" : "201-478-4678" 
      } 
     } 
    } 
} 
+0

是啊!但重點在於,公司可能有幾個電話號碼。因此,它使得深層次。至少在一個級別上。我閱讀了Firebase的db結構示例,並找到了類似的例子。 https://firebase.google.com/docs/database/android/structure-data#avoid_nesting_data –