【发布时间】:2019-03-04 20:26:14
【问题描述】:
我正在做一个登录系统,我正在查询用户的条目以验证它是否存在于 firestore,如果它找到他的输入,那么我将它登录到控制台。在这部分一切正常之前,当他输入存在的东西时,它会带来他的数据。但是,当他输入不存在的东西时,它会输入一个空数组“[]”,这意味着不存在这样的东西。我的问题很简单,当他的输入不存在时,我找不到合适的逻辑来控制台日志,仅此而已。
这是我的代码
pageLogin() {
var auxint = 0;
this.dataAux
let auxString = '[';
var query = firebase.firestore().collection("armazenaTest")
query.where('Documento.login', '==', this.User.login).get().then(res => {
res.forEach(item => {
if (item.exists) {
auxint++;
auxString += '{"id":"' + item.id + '","armazenaTest":' + JSON.stringify(item.data()) + '}';
if(item.get('Documento.login') == this.User.login){
console.log('Document found!: ', item.data())
}
}
if (res.size != auxint)
auxString += ', ';
})
auxString += ']';
this.dataJSON = JSON.parse(auxString);
console.log(this.dataJSON);
}).catch(err => {
console.log('An error occured ' + err);
});
}
【问题讨论】:
标签: angular typescript ionic-framework google-cloud-firestore