Firebase:如何避免嵌套回调?

时间:2016-08-24 07:27:49

标签: android firebase callback firebase-realtime-database

根据官方Firebase文档(https://firebase.google.com/docs/database/android/structure-data),建议以这种格式构建数据:

// An index to track Ada's memberships
{
  "users": {
    "alovelace": {
      "name": "Ada Lovelace",
      // Index Ada's groups in her profile
      "groups": {
         // the value here doesn't matter, just that the key exists
         "techpioneers": true,
         "womentechmakers": true
      }
    },
    ...
  },
  "groups": {
    "techpioneers": {
      "name": "Historical Tech Pioneers",
      "members": {
        "alovelace": true,
        "ghopper": true,
        "eclarke": true
      }
    },
    ...
  }
}

以下是我对回调流程的理解(通过回调我引用 onDataChange addValueEventListener / addListenerForSingleValueEvent

Callback for -groups-
....In a loop Callback for each of the members (to get details from -users- node)
........Another Callback if -users- has a field for which data is at a different node 

依此类推。

这种结构可以导致嵌套回调场景,如果是,如何避免它呢?

0 个答案:

没有答案