我正在開發一個串列應用程式,并使用 firebase 作為我的后端,在我添加 .orderBy 陳述句以通過創建日期對資料進行排序之前,一切正常,我可以在應用程式上更新新帖子,但是在我添加 .orderBy( 'createdAt', 'desc') 在串列中,我無法更新任何新帖子,并且出現錯誤 “TypeError: listingsRef.add is not a function. (In 'listingsRef.add(updatedUploadObjects)', 'listingsRef.add ' 未定義) 代碼如下所示:
import { setFavoriteItems } from '../../../favorites/redux'
import { firebase } from '../../../api/firebase/config'
import ServerConfiguration from '../../../../ServerConfiguration'
const savedListingsRef = firebase
.firestore()
.collection(ServerConfiguration.database.collection.SAVED_LISTINGS)
.orderBy('createdAt', 'desc')
const listingsRef = firebase
.firestore()
.collection(ServerConfiguration.database.collection.LISTINGS)
.orderBy('createdAt','desc')
const ListingCategoriesRef = firebase
.firestore()
.collection(ServerConfiguration.database.collection.CATEGORIES)
.orderBy('order')
還有這個:
if (selectedItem) {
listingsRef
.doc(selectedItem.id)
.update({ ...updatedUploadObjects, photo: coverPhoto })
.then(docRef => {
callback({ success: true })
})
.catch(error => {
console.log(error)
callback({ success: false })
})
} else {
listingsRef
.add(updatedUploadObjects)
.then(docRef => {
if (docRef.id) {
listingsRef
.doc(docRef.id)
.update({ id: docRef.id, photo: coverPhoto })
}
callback({ success: true })
})
.catch(error => {
console.log(error)
callback({ success: false })
})
}
}
uj5u.com熱心網友回復:
這定義了一個CollectionReference:
const savedListingsRef = firebase
.firestore()
.collection(ServerConfiguration.database.collection.SAVED_LISTINGS)
如果您檢查該鏈接,您將看到 aCollectionReference有一個add方法,這意味著您可以向其中添加一個檔案。
這定義了一個Query:
const savedListingsRef = firebase
.firestore()
.collection(ServerConfiguration.database.collection.SAVED_LISTINGS)
.orderBy('createdAt', 'desc')
如果您檢查最后一個鏈接,您將看到查詢沒有add方法,因此您不能add對查詢進行任何操作。
你也會想保持CollectionReference周圍,??這樣你就可以打電話add()了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/386105.html
標籤:javascript 火力基地 反应原生 谷歌云firestore
上一篇:為什么FirebaseCloudMessagingWeb客戶端messages.getToken()有時會產生不同的令牌?(相同的瀏覽器,相同的標簽)
