Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript firestore类型错误:无法读取属性';州';未定义_Javascript_Google Cloud Firestore - Fatal编程技术网

javascript firestore类型错误:无法读取属性';州';未定义

javascript firestore类型错误:无法读取属性';州';未定义,javascript,google-cloud-firestore,Javascript,Google Cloud Firestore,TypeError:无法读取未定义的属性“state”。我试图在firestore中获取文档的pr_集群,但出现错误 this.props.firebase.cartItems().doc(authUser.uid).collection('products').limit(1).onSnapshot(function(querySnapshot) { querySnapshot.forEach(

TypeError:无法读取未定义的属性“state”。我试图在firestore中获取文档的pr_集群,但出现错误

this.props.firebase.cartItems().doc(authUser.uid).collection('products').limit(1).onSnapshot(function(querySnapshot) {
                
                
                querySnapshot.forEach(function(doc) {
                
                    this.state.pr_cluster = doc.data().pr_cluster;
                    
                    
                            });
                            
                
            });

您应该使用arrow函数来避免在forEach回调中重新定义此

querySnapshot.forEach(doc => {
    this.state.pr_cluster = doc.data().pr_cluster;
});

非常感谢你,先生