[英]I want to display only documents with matching fields in firebase
As in the title, I want to show only documents with matching fields in Firebase.如标题所示,我只想在 Firebase 中显示具有匹配字段的文档。
Now my code using jquery looks like this:现在我使用 jquery 的代码如下所示:
const db = firebase.firestore(); db.collection('product').get().then((product)=>{ product.forEach((doc)=>{ var li = ""; console.log(doc.data()) if(topic == doc.data().topic){ li = ` <div> <img class="${img}" src="${doc.data().img}"> <p class="text-500 text-white">${doc.data().title}</p> </div> ` }else{ li = ` <div> <img class="${img}" src="${doc.data().img}"> <p class="text-500 text-white">${doc.data().title}</p> </div> ` } $(`.app`).append(li) }) });
<div class="app"></div>
All documents are now available.现在所有文件都可用。 For example, if the current URL is "https://example.com?topic=firebase", I want to display only the contents of the documents with the topic field firebase in the documents in a collection called product.
例如,如果当前的 URL 是“https://example.com?topic=firebase”,我想只显示文档中主题字段 ZBF12E1515C25C7D8C0352F1413AB91 中名为产品的集合的文档的内容。
Thank you in advance.先感谢您。
To get the value of the URL parameter "topic", try this:要获取 URL 参数“主题”的值,请尝试以下操作:
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
const topic = getParameterByName("topic", window.location.href);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.