0

Everything is nice when you have only one array.

var ref = new Firebase("...");
var sync = $firebase(ref);
var test =  sync.$asArray();

So I have an array in test on which I can operate with $add, $save and $remove.

But what if I want a second array? I've tried this:

var ref = new Firebase("...");
var sync = $firebase(ref);
var test =  sync.$asArray();
var test2 =  sync.$asArray();

But if I add something to test2, it goes to the same DB as the one test uses. Am I using it wrong? Do I need to create a new Firebase db for each array?

Is it possible to create a dynamic number of arrays? Is it possible, to nest arrays into arrays? Example: a list of todo lists.

2 Answers 2

1

In your example you call $asArray on the same $firebase sync twice, so naturally this leads to two references to the same array.

If you want two separate arrays, you'll need to set up a separate reference to the data for each of them:

var ref1 = new Firebase("https://yours.firebaseio.com/array1");
var ref2 = new Firebase("https://yours.firebaseio.com/array2");
var sync1 = $firebase(ref1);
var sync2 = $firebase(ref2);
var test =  sync1.$asArray();
var test2 =  sync2.$asArray();
Sign up to request clarification or add additional context in comments.

1 Comment

WOW, thanks! I have tried it with a new instance, but I've used the same URL. Silly me. The nesting is still an issue 'tho. Of course, I can use a list, to store the URL-s of the sublists, but a simple main.$add(sub) would be much more elegant.
0

It wasn't an easy ride, but finally I found a simple way to do this. Check it out here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.