简体   繁体   English

如何从Firebase数据库中的对象获取数据?

[英]How to get data from an object in Firebase database?

I have the following structure on my firebase database , what i want is that when ever user clicks on submit , it retrieves all the ads with that specified category value since i have pushed category(option) value to fire base database ie 1,2,3,4. 我在firebase数据库上具有以下结构,我想要的是,当用户单击 Submit 时,它会检索具有指定类别值的所有广告,因为我已将category(option)值推送到fire base数据库,即1,2, 3,4。

Fire base structure: 防火底座结构:

在此处输入图片说明

and my html code is : 和我的HTML代码是:

<form class=" jumbotron browseCategory bs1">
    <h3 class="catSearch">SEARCH ADS USING CATEGORY SEARCH</h3> <br/> <hr/>
        <div class="form-group">
                    <label for="formGroupExampleInput2"> Select your category : </label>
                <select id="myselect">
                    <option value="1">Mobile</option>
                    <option value="2">Electronics</option>
                    <option value="3">Property</option>
                    <option value="4">Cosmetics</option>
                  </select> </div>
 <button type="submit" class="btn btn-primary" id="submission_cat">Search Ad of this Category</button>
    </form>

To filter ads by adCategory you may use: 要按adCategory过滤广告,您可以使用:

  let ref = firebase.database().ref("ADS");
    ref.orderByChild("adCategory").equalTo("1").on("child_added", function(snapshot) {  
    console.log(snapshot.key);
    });

and hook it up to your submit handler function 并将其连接到您的提交处理程序函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM