How to manage dynamic path in app to Firebase data

后端 未结 1 1801
梦毁少年i
梦毁少年i 2021-01-15 02:12

I have data in my Firebase that looks something like this (this is a Javascript-based web app):

bids
    400
        1
            50.00
        2
                   


        
相关标签:
1条回答
  • 2021-01-15 02:52

    Since you're building your query like this:

    dataRef.child('bids').child(auction).child(lotno).on(...
    

    You will have to create attach a new listener (and turn off the existing listener) every time one of the action or lotno variables changes.

    It sounds like there can only be a single current lot at a time, which might make it more useful to model that into your data model:

    bids
        400
            1
                50.00
            2
                60.00
        401
            1
                55.00
            current
                65.00
    

    Then once the bidding on the current lot has finished, you can "retire" it to its proper lotnumber slot and have the next lot become the current. With a data structure like this, your listener for an auction could always be watching current:

    dataRef.child('bids').child(auction).child('current').on(...
    
    0 讨论(0)
提交回复
热议问题