firestore字符串工作但变量不工作,为什么

时间:2018-06-08 13:33:12

标签: javascript reactjs firebase google-cloud-firestore

当我写这个

var ref = Cloud.collection('Groups').doc(Option)
 .collection('India').doc('Info')

 ref.get().then(function(fields){
    var data = fields.data()
    alert(data)
    totalposts = data.TotalPosts
    alert('totalposts : ' +  totalposts)    
    postnum = totalposts + 1;    
    alert('postnum : ' + postnum)
            })

它工作得非常好但是当我这样做时: -

      var abc = 'India'
var ref = Cloud.collection('Groups').doc(Option)
 .collection(abc).doc('Info')    
 ref.get().then(function(fields){
    var data = fields.data()
    alert(data)
    totalposts = data.TotalPosts
    alert('totalposts : ' +  totalposts)

    postnum = totalposts + 1;

    alert('postnum : ' + postnum)

它说未定义并给我一个错误我被困6个小时而且真的很难过请帮帮我

Unhandled Rejection (TypeError): Cannot read property 'TotalPosts' of undefined

0 个答案:

没有答案