基本上,我正在研究whatsapp克隆,并且在搜索当前用户的联系人时遇到了问题。
这是第一个代码
this._user.getContacts(this.el.inputSearchContacts.value);
该函数位于一个函数内,当您将输入聚焦时按任意字母或数字,它将开始将输入内部的内容发送到“ getContacts”函数
getContacts(fillter = ""){
return new Promise((resolve, reject)=>{
User.getContactsRef(this.email).where("nameLowerCase", ">=", (fillter)? fillter.match( /([a-z])\+w/gi) : fillter).onSnapshot(docs=>{
here goes the rest of the function
}
在此处应用填充器的地方,应该做的是获取您输入中输入的名称,并将其与用户联系人列表中的联系人名称匹配,以仅显示匹配的联系人,但这是此错误出现的地方:
Uncaught (in promise) FirebaseError: Invalid query. Null supports only equality comparisons.
at new FirestoreError (webpack:///./node_modules/@firebase/firestore/dist/index.cjs.js?:351:28)
at Function.FieldFilter.create (webpack:///./node_modules/@firebase/firestore/dist/index.cjs.js?:9830:23)
at CollectionReference.Query.where (webpack:///./node_modules/@firebase/firestore/dist/index.cjs.js?:22151:34)
at eval (webpack:///./src/model/User.js?:87:41)
at new Promise (<anonymous>)
at User.getContacts (webpack:///./src/model/User.js?:85:14)
at HTMLInputElement.eval (webpack:///./src/controller/WhatsAppController.js?:401:20)
FirestoreError @ index.cjs.js:351
FieldFilter.create @ index.cjs.js:9830
Query.where @ index.cjs.js:22151
eval @ User.js:87
getContacts @ User.js:85
eval @ WhatsAppController.js:401
因此,有人可以告诉我我在做什么错吗?
最佳答案
不支持您尝试执行的操作。 Firestore完全不提供正则表达式搜索。您只能将字符串与>=
,==
和<=
进行比较。
错误消息告诉您三元表达式:
(fillter)? fillter.match( /([a-z])\+w/gi) : fillter
产生一个空值,对于您要Firestore在该字段上执行的
>=
比较而言,它不是有效值。