Firebase Reference.child失败:第一个参数是无效路径=“ [object Object]”

时间:2019-06-30 22:30:35

标签: javascript firebase react-native firebase-realtime-database

我正在尝试使用新值更新数据库中的记录,但是我得到了 Reference.child失败:第一个参数是无效路径=“ [object Object]”错误。

onPressAdd = async(keyPlants) => {
   if (this.state.newNote === '') {
      alert('Note is blank');
      return;
   }
   currentUser = await firebase.auth().currentUser

   firebase.database().ref(currentUser.uid).child('plantList').child(keyPlants).update({
     note: this.state.newNote
   });
 }

我尝试使用var keyPlantss = String(keyPlants)在函数内创建新变量,并将其传递给数据库ref,但错误相同。

keyPlants是通过导航传递的数据库中的值

const { navigation } = this.props;
const keyPlants = navigation.getParam('keyPlant');

这是我的数据库结构的样子:

{
  "Rv2qgEYdLyR5njO8LAALWpgwbeB2" : {
    "monday" : {
      "-LidETJkPbBEaaKTzr_k" : {
        "nameC" : "tapertip onion",
        "nameS" : "Allium acuminatum"
      }
    },
    "plantList" : {
      "-LicubjdvSIrA8Z7V4vW" : {
        "bloom" : "Summer",
        "drought" : "Medium",
        "fcolor" : "Purple",
        "gperiod" : "Spring and Summer",
        "lifespan" : "Short",
        "mheight" : 30.478512648582743,
        "moisture" : "Low",
        "nameC" : "tapertip onion",
        "namePlant" : "Allium acuminatum",
        "pcURL" : "https://upload.wikimedia.org/wikipedia/commons/2/21/Alliumacuminatum.JPG",
        "toxicity" : "None"
      },
      "-Liy_JT1VyqiqmY82dLN" : {
        "bloom" : "",
        "drought" : "",
        "fcolor" : "",
        "gperiod" : "",
        "lifespan" : "",
        "mheight" : "",
        "moisture" : "",
        "nameC" : "",
        "namePlant" : "Tanacetum pilosum",
        "pcURL" : "",
        "toxicity" : ""
      }
    },
    "thursday" : {
      "-LiyEo6s5QgNj3rqura4" : {
        "nameC" : "tapertip onion",
        "nameS" : "Allium acuminatum"
      }
    },
    "tuesday" : {
      "-Liya4u6LnbJSbkAx9ji" : {
        "nameC" : "",
        "nameS" : "Tanacetum pilosum"
      }
    }
  }
}

0 个答案:

没有答案