React Native - 使用componentWillMount的Tab Navigator

时间:2018-02-26 00:39:31

标签: reactjs function native mount tabnavigator

如何在此类中调用componentWillMount方法?

db.getCollection('property').aggregate([
  {"$unwind":"$data"},
  {"$group":{"_id":{"id":"$_id","name":"$data.name", "location":"$data.location"},"data":{"$push":"$data"}}},
  {"$project":{
    "values":{
      "$reduce":{
        "input":"$data",
        "initialValue":{
              "power":0,
              "ac":0,
              "fan":0,
              "light":0
            },
        "in":{
          "$let":{
            "vars":{
              "ac":{
                "$sum":{
                  "$let":{
                    "vars":{"acm":{"$filter":{"input":"$$this.ac","as":"ac","cond":"$$ac.on"}}},
                    "in":"$$acm.power"
                  }
                }
              },
              "fan":{
                "$sum":{
                  "$let":{
                    "vars":{"fanm":{"$filter":{"input":"$$this.fan","as":"fan","cond":"$$fan.on"}}},
                    "in":"$$fanm.power"
                  }
                }
              },
              "light":{
                "$sum":{
                  "$let":{
                    "vars":{"lightm":{"$filter":{"input":"$$this.light","as":"light","cond":"$$light.on"}}},
                    "in":"$$lightm.power"
                  }
                }
              }
            },
            "in":{
              "power":{"$add":["$$value.power", {"$sum":["$$ac","$$fan","$$light"]}]},
              "ac":{"$add":["$$value.ac", "$$ac"]},
              "fan":{"$add":["$$value.fan", "$$fan"]},
              "light":{"$add":["$$value.light", "$$light"]}
            }
          }
        }
      }
    }
  }},
  {"$group":{"_id":"$_id.id", "split":{"$push":{"name":"$_id.name","location":"$_id.location","values":"$values"}}}},
  {"$addFields":{
    "aggr":{
      "ac":{"$sum":"$split.values.ac"},
      "fan":{"$sum":"$split.values.fan"},
      "light":{"$sum":"$split.values.light"},
      "power":{"$sum":"split.values.power"}
    }
  }}
])

我要做的是调用resetAction来重置所有导航状态。但是,我不想单独为每个选项卡(Friends和Moms)实现它,而只是在我的TabNavigator类中调用它一次(例如在componentWillMount中)。

P.S。我想要使用redux。

1 个答案:

答案 0 :(得分:0)

您可以在声明TabNavigator之前调用重置操作,不需要componentWillMount。

您可以检查当前routeName,如果它在选项卡导航器初始路由中触发重置操作