Monday 15 April 2013

list - Trouble accessing child objects in Firebase -


I'm trying to drag a list of users connecting to a select dropdown in my firebase. It is that I am unable to use child objects properly.

Uses the user.UserName (see below code), but only for my own user data, it does not drag anything else. / P>

It was sort of changing "userListRef.on" from "myUserRef.on" and using something like "snapshot.child" ('username'). Should, but it just throws undefined. To do the same, "userListRef.on" ('child_added') goes to "connectedUsers.child.userName", I'm sure I'm missing something simple here.

In the code given below, the function (snapshot) "I can successfully add and remove user data from firebase, and log all objects into the console and when I drill the object, all the data looks fine. Just one way to access data So that I can remove all connected users in some selected dropdown or remove them when they disconnect

  on userListRef = new Firebase ('https://myaccount.firebaseIO.com/users / '); On myUserRef = userListRef.push (); // add userId = $ (' # myIdInput ') to the firebase on Val (); Username = $ (' # nameInput '); Val (); MyUserRef.push ({userId: .. userId, user name: uSERNAME}); // read user objects and fire adduser function myUserRef.on ('child_added', function (snapshot) {var connectedUsers = snapshot.val (); / / Adduser (connectedUsers; Console.log (adduser). UserId, connected user.assername);}); // Add user to SEL ECT dropdown function addUser (userId, userName) {var modSelect = $ ('# tsmmodsendto'); ModSelect.append ($ ('& lt; option & gt; & lt; / option & gt;'). Attr ("value", userId) .text (userName)); } USER objects and fire REMOVEUSER function myUserRef.on ('child_removed', function (snapshot) {var connectedUsers = snapshot.val () read //; console.log (removeUser); //removeUser (connected) users.userId, connectedUsers.userName );}); // User to delete user drop down function (user ID, username) {var modSelect = $ ('# tsmmodsendto'); ModSelect.append ($ ('& lt; option & gt; & lt; / option & gt;') RemoveAttr ("value", userId) .text (userName)); } // ON DisconnectNetRemove User Data FIREBASE myUserRef.onDisconnect (). Remove ();    

The code you write will not work properly because every user is typing Is:

/ user / PUSH_ID / PUSH_ID

and then listening:

/ users / PUSH_ID

so every customer will go Just listening for your data and never seeing anyone else's data, to see the data of other people, you should listen / write to everyone on the same path.

In your question, you mention that if you change the listening of the user / you can see "undefined" you can simplify your code, and use that approach, and Maybe I can provide a more helpful answer?

Or if I can not understand correctly, please make your questions simple and clear.

No comments:

Post a Comment