简体   繁体   English

我只想在 firebase 中显示具有匹配字段的文档

[英]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.

相关问题 我想在 javascript 中的控制台中显示匹配的记录 - i want to display the matching records in the console in javascript 正则表达式在 MongoDB 中查找多个字段的匹配文档 - RegExp to find matching documents in MongoDB for multiple fields 如何遍历 Firebase 文档以查找匹配的文档,然后提取名称? - How do I loop through Firebase documents for a matching document, then extract the name? 寻找正则表达式以仅获取我想要的字段 - Looking to find a Regular Expression to fetch only the fields I want 仅在以下情况下才显示页面 - Want to display page only if 我只想在列表中显示重复的项目一次,然后删除其他项目 - I want to display repeated items in list only once and remove others 我只希望 div 根据布尔值显示在屏幕上 - I only want a div to display on screen depending on a boolean value 我想只向一个有这种情况的用户显示,但收到此错误: - i want to display to only one user with this condition but getting this error: 如果只有用户名可用,我想在 php 中启用表单字段,否则字段应保持禁用状态 - I want to enable form fields in php if only username is available otherwise the fields should remain disabled 只读取 firebase 中的某些字段 - read only certain fields in firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM