第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Javascript 中的 Where() 方法中放置變量?

如何在 Javascript 中的 Where() 方法中放置變量?

慕少森 2022-07-21 22:10:38
對不起這個問題,因為我是這個領域的新手。因此,我目前正在為我的網(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>
查看完整描述

1 回答

?
狐的傳說

TA貢獻1804條經(jīng)驗 獲得超3個贊

既然source是一個變量,那么您需要執(zhí)行以下操作:


source = target1.value;

source = source.toLowerCase();

db.collection('Product').where('name','>=', source).where('name','<=', source + '\uf8ff').onSnapshot(snapshot =>{



查看完整回答
反對 回復 2022-07-21
  • 1 回答
  • 0 關(guān)注
  • 398 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號