javascript - After Initial Load Child_Added no longer returns full data -
I have a site where a user can order by selecting items in a menu
It is set up so that you press the "position order" button on the menu page
Then the ordered order appears on the order page.
On the orders.html page to load first, it shows all the data ok but whatever the added child does not load the rest of the data added, or it displays does not do. If I refresh all the loaded orders page
I may feel somewhat simpler, but I think where I found the fault.
Edit: Orders.html code from webpage.
var base = new firebase ('https://takeaway.firebaseio.com/'); ('Hair' added '', 'function' (snapshot), function (snapshot) {var orderdata = snapshot.val (); var contactname = orderdata.scope name; var contact number = orderdata contact number; var orderotal = orderdata Quotes; var command = "& lt; div class = 'openorder' gt; & lt; span class = 'name' & gt;" + contact name + " }); Order = order + "& lt; / div> gt; & lt; span class = 'total' & gt; + Order total "& lt; / span & gt; & lt; / div & gt; $ ('# Order') enclosed (order). });
tl;
In the firebase, child_added event triggers only when the child is added when the child is updated later, Event is triggered. causes your problem
In the menu.html, first you have to push popup a new order and then order items: < Pre> var description = base.chid ('order'). Push ({Contact Name: Contact Name, Contact Number: Contact Number, Total Cost: Total Cost}); Var detailRef = details.name (); $ ('# Selected & gt; walk away'). Each (function () {var itemName = $ (this). Child ("title"). Text (); var itemCost = $ (this) children (". (". "Chosen"); < / Pre> Display more details on the order you listen to child_added in order: base.child ('order') ('Child_added', function (snapshot) {var orderData = snapshot.val (); var contactName = orderData. Contact; var contact number = orderdata contact number; var ordotool = orderdata totalcost; var order = "& lt ; Div class = 'openOrder' & gt; & lt; span class = 'name' & gt; "+ contactname +" + + & gt; Lt; span class = 'number' & gt; "+ contact number +" is turned on (function (ITEMST) { ). At the time of the new order Items are not yet filled, so there is nothing to display / P>
when you add items, then on child_added event order There is no fire from, because there is no new order. A Possible Solution
Solution First type the full command in menu.html and then press it on Firebase. Since you can arbitrarily send complex javascript objects into firebase, your data structure will be the same.
A simplified sample:
var order = {ContactName: ContactName, ContactNumber: Contact number, Total: TotalCast}; order. ITEMS = []; $ ('# Selected & gt; walk away'). Children ("(cost."). Push ({name: itemName, cost: itemCost});}); . Base.child ('command') push (order); An added advantage is that it will save you a lot of time between the client and the server.
Comments
Post a Comment