Javascript Firebase.push失败:第一个参数包含无效键($$typeof)

Javascript Firebase.push失败:第一个参数包含无效键($$typeof),javascript,android,reactjs,firebase,react-native,Javascript,Android,Reactjs,Firebase,React Native,我第一次学习react-native是为了开发android应用程序而不是IOS-one,我学习了youtube上的react-native和Firebase教程构建一个简单的ToDo应用程序。但我在尝试添加项目时出错。我得到以下错误 Firebase.push失败:第一个参数在属性“restaurant.restaurant\u name.targetist.\u nativeParent.\u currentElement”中包含无效键($$typeof)。键必须是非空字符串,不能包含“.”

我第一次学习react-native是为了开发android应用程序而不是IOS-one,我学习了youtube上的react-native和Firebase教程构建一个简单的ToDo应用程序。但我在尝试添加项目时出错。我得到以下错误

Firebase.push失败:第一个参数在属性“restaurant.restaurant\u name.targetist.\u nativeParent.\u currentElement”中包含无效键($$typeof)。键必须是非空字符串,不能包含“.”、“#”、“美元”、“/”和“[”

是什么造成了这个问题

import React, { Component } from 'react';

import Firebase from 'firebase';

import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableHighlight,
  TextInput,
  ListView
} from 'react-native';

class foodOrderSystem extends Component {
  constructor(props){
    super(props);
    const firebaseRef = new Firebase('foodordersystem.firebaseio.com');
    console.log(firebaseRef);
    this.itemRef = firebaseRef.child('restaurant');
    this.state = {
        newRestaurant:'',
        // estimated_delivery:'',
        // description:'',
        restaurantSource: new ListView.DataSource({rowHasChanged: (row1,row2) => row1 !== row2})
    };
    this.restaurant = [ ];
  }

  componentDidMount() {
    this.itemRef.on('child_added', (snap) => {
        this.restaurant.push({
            id:snap.key(),
            text:snap.val()
        });
        this.setState({
            restaurantSource:this.state.restaurantSource.cloneWithRows(this.restaurant)
        });
    });

    this.itemRef.on('child_removed', (snap) => {
        this.restaurant = this.restaurant.filter((x) => x.id !== snap.key());
        this.setState({
            restaurantSource:this.state.restaurantSource.cloneWithRows(this.restaurant)
        });
    });

  }

  addRestaurant(){
    if(this.state.newRestaurant !== ''){
        this.itemRef.push({
            restaurant_name: this.state.newRestaurant
        });
        this.setState({ newRestaurant:''});
    }
  }

  removeRestaurant(rowData){
    this.itemRef.child(rowData.id).remove();
  }

  render() {
    return (
      <View style={styles.appContainer}>
        <View style={styles.titleView}>
            <Text style={styles.titleText}>
              foodOrderSystem
            </Text>
        </View>
        <View style={styles.inputcontainer}>
            <TextInput 
                style={styles.input} 
                onChange={(text) => this.setState({newRestaurant:text})}
                value={this.state.newRestaurant} />
                <TouchableHighlight
                    style={styles.button}
                    onPress={ () => this.addRestaurant() }
                    underlayColor="#00ffff">
                    <Text style={styles.btnText}>Add</Text>
                </TouchableHighlight>
        </View>
        <ListView
            dataSource={this.state.restaurantSource}
            renderRow={this.renderRow.bind(this)} />
      </View>
    );
  }

  renderRow(rowData){
    return(
        <TouchableHighlight
            underlayColor="#dddddd"
            onPress={() => this.removeRestaurant(rowData)}>
            <View>
                <View style={styles.row}>
                    <Text style={styles.todoText}>{rowData.text}</Text>
                </View>
                <View style={styles.separator} />
            </View>
        </TouchableHighlight>
    );
}
}

const styles = StyleSheet.create({
  appContainer:{
    flex: 1
  },
  titleView:{
    backgroundColor: '#48afdb',
    paddingTop: 30,
    paddingBottom: 10,
    flexDirection: 'row'
  },
  titleText:{
    color: '#fff',
    textAlign: 'center',
    fontWeight: 'bold',
    flex: 1,
    fontSize: 20,
  },
  inputcontainer: {
    marginTop: 5,
    padding: 10,
    flexDirection: 'row'
  },
  button: {
    height: 36,
    flex: 2,
    flexDirection: 'row',
    backgroundColor: '#48afdb',
    justifyContent: 'center',
    color: '#FFFFFF',
    borderRadius: 4,
  },
  btnText: {
    fontSize: 18,
    color: '#fff',
    marginTop: 6,
  },
  input: {
    height: 36,
    padding: 4,
    marginRight: 5,
    flex: 4,
    fontSize: 18,
    borderWidth: 1,
    borderColor: '#48afdb',
    borderRadius: 4,
    color: '#48BBEC'
  },
  row: {
    flexDirection: 'row',
    padding: 12,
    height: 44
  },
  separator: {
    height: 1,
    backgroundColor: '#CCCCCC',
  },
  todoText: {
    flex: 1,
  },
});

AppRegistry.registerComponent('foodOrderSystem', () => foodOrderSystem);
import React,{Component}来自'React';
从“Firebase”导入Firebase;
进口{
评估学,
样式表,
文本,
看法
触控高光,
文本输入,
列表视图
}从“反应本机”;
类foodOrderSystem扩展组件{
建造师(道具){
超级(道具);
const firebaseRef=new Firebase('foodordersystem.firebaseio.com');
控制台日志(firebaseRef);
this.itemRef=firebaseRef.child(“餐厅”);
此.state={
新餐厅:'',
//预计交付量:'',
//说明:“”,
restaurantSource:new ListView.DataSource({rowHasChanged:(row1,row2)=>row1!==row2})
};
这家餐厅=[];
}
componentDidMount(){
this.itemRef.on('child_added',(snap)=>{
这是餐厅({
id:snap.key(),
文本:snap.val()
});
这是我的国家({
restaurantSource:this.state.restaurantSource.cloneWithRows(this.restaurant)
});
});
this.itemRef.on('child_removed',(snap)=>{
this.restaurant=this.restaurant.filter((x)=>x.id!==snap.key());
这是我的国家({
restaurantSource:this.state.restaurantSource.cloneWithRows(this.restaurant)
});
});
}
addRestaurant(){
如果(this.state.newRestaurant!=''){
这个.itemRef.push({
餐厅名称:this.state.newRestaurant
});
this.setState({newRestaurant:'});
}
}
清除剂(rowData){
this.itemRef.child(rowData.id).remove();
}
render(){
返回(
食品系统
this.setState({newRestaurant:text})
value={this.state.newRestaurant}/>
this.addRestaurant()}
underlayColor=“#00ffff”>
添加
);
}
renderRow(行数据){
返回(
this.removestaurant(rowData)}>
{rowData.text}
);
}
}
const styles=StyleSheet.create({
appContainer:{
弹性:1
},
标题视图:{
背景颜色:“#48afdb”,
paddingTop:30,
填充底部:10,
flexDirection:“行”
},
标题文字:{
颜色:“#fff”,
textAlign:'中心',
fontWeight:'粗体',
弹性:1,
尺寸:20,
},
输入容器:{
玛金托普:5,
填充:10,
flexDirection:“行”
},
按钮:{
身高:36,
弹性:2,
flexDirection:'行',
背景颜色:“#48afdb”,
为内容辩护:“中心”,
颜色:“#FFFFFF”,
边界半径:4,
},
btnText:{
尺码:18,
颜色:“#fff”,
玛金托普:6,
},
输入:{
身高:36,
填充:4,
marginRight:5,
弹性:4,
尺码:18,
边框宽度:1,
边框颜色:“#48afdb”,
边界半径:4,
颜色:“#48BBEC”
},
行:{
flexDirection:'行',
填充:12,
身高:44
},
分离器:{
身高:1,,
背景颜色:“#中交”,
},
todoText:{
弹性:1,
},
});
AppRegistry.registerComponent('foodOrderSystem',()=>foodOrderSystem);
这是错误的附件


Hi@pri!所有这些代码都是重现问题所必需的吗?看起来你刚刚发布了整个应用程序并要求我们进行调试。你能将其简化为相关代码吗?请参阅。@Kato我已经简化了代码。问题在.push()中.密钥是否包含$$typeof?嘿..我已经尝试了你的代码…我没有得到你得到的错误。它对我有效。但是在更新到firebase后,我在“restaurantSource:this.state.restaurantSource.cloneWithRows(this.restaurant)”行中遇到了一个错误。你有什么解决方案吗?