firebase set failed第一个参数包含属性中的undefined

时间:2017-05-29 16:05:44

标签: json firebase react-native firebase-realtime-database redux

当我创建一个事件时,我这样做:

export const eventCreate = ({ title, time, location }) => {
  const newPostKey = firebase.database().ref('/events').push().key;
  const update = {};

  const postDetails = {
    eventId: newPostKey,
    title,
    ...
    goingNumber: 1,
    ...
  };

  update[`/events/${newPostKey}`] = postDetails;

  return (dispatch) => {
    firebase.database().ref()
      .update(update)
      .then(() => {
        dispatch({ type: EVENT_CREATE });
      })
      .then(() => newPostKey);
  };
};

在数据库中:

enter image description here

稍后我尝试更新goingNumber

export const eventSave = ({ goingNumber, eventId }) => {    
  return (dispatch) => {
    firebase.database().ref(`/events/${eventId}`)
      .set({ goingNumber })
      .then(() => {
        dispatch({ type: EVENT_SAVE_SUCCESS });
      });
  };
};

我收到此错误说:

enter image description here

1 个答案:

答案 0 :(得分:1)

您没有传递goingNumber的值。我的猜测是你正在寻找

firebase.database().ref(`/events/${eventId}`)
        .child('goingNumber').set(goingNumber )