對不起這個問題,因為我是這個領域的新手。因此,我目前正在為我的網(wǎng)站使用 Firebase Firestore,從 Firebase 獲取文檔的常用方法運行良好。但是,當我創(chuàng)建搜索功能時,我必須通過where('field name in Firebase','equations like "=", ">",">=", etc.', 'parameter'). 我的問題是我想從我調(diào)用的搜索欄中輸入一個值source。轉(zhuǎn)換sourcewith的值后toLowerCase(),我想將變量分配給source函數(shù)內(nèi)部的參數(shù)where()。但是,它不能很好地工作,因為在我看過的一些教程中,他們使用字符串數(shù)據(jù)類型并將其放在where()參數(shù)中。誰能幫我解決這個問題?順便說一句,我試著輸入一些string在參數(shù)內(nèi)部,它運行良好。我會將數(shù)據(jù)保留在 Firebase 中,以防您想弄亂它。謝謝你。target1.addEventListener('search', search);function search(){ source = target1.value; source = source.toLowerCase(); db.collection('Product').where('name','>=', 'source').where('name','<=', 'source' + '\uf8ff').onSnapshot(snapshot =>{ let changes = snapshot.docChanges(); changes.forEach(change =>{ if (change.type == 'added'){ insertDoc(change.doc); } else if (change.type == 'removed'){ let box = docTarget.querySelector('[data-id=' + change.doc.id +']'); docTarget.removeChild(box); } })})<html><head> <title>SDE Stock | Cari</title> <meta charset="utf-8"> <link rel="stylesheet" href="style.css"> <link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap" rel="stylesheet"> <!-- The core Firebase JS SDK is always required and must be listed first --> <script src="https://www.gstatic.com/firebasejs/7.14.0/firebase-app.js"></script> <script src="https://www.gstatic.com/firebasejs/7.14.0/firebase-firestore.js"></script> <!-- TODO: Add SDKs for Firebase products that you want to use https://firebase.google.com/docs/web/setup#available-libraries --> <script src="https://www.gstatic.com/firebasejs/7.14.0/firebase-analytics.js"></script></head></body></html>
如何在 Javascript 中的 Where() 方法中放置變量?
慕少森
2022-07-21 22:10:38