Reputation: 11157
I have this nodes, the ref childs have randomID.
master: {
123: {
text: "hello world"
},
456: {
text: "hello world 2"
}
}
ref: {
abc: {
123: 1,
456: 1
},
efg: {
456: 1
}
}
I want to loop the ref
and it refToMaster
. How to query using FirebaseIndex ?
new FirebaseIndex(ref.child(STUCK_HERE), master);
UPDATE
I updated my node structure to what hiattp and kato mentioned.
Sorry for my unclear question, I re-edit this. Actually I want to retrieve both ref.abc
and ref.efg
and also retrieve their related master data which are 123
and 456
Below is what I have tried.
angularFireCollection(ref, function(s) {
s.forEach(function(cs){
//cs.name() - So I can get abc and efg and put in FirebaseIndex
var index = new FirebaseIndex(ref.child(cs.name()), master);
$scope.foos = angularFireCollection(index);
//I stuck here, must be something wrong.
})
})
Upvotes: 0
Views: 201
Reputation: 40582
@hiattp has noted the standard format for FirebaseIndex. This is the intended use case.
You can also pass a function into the dataRef
for FirebaseIndex, which would allow you to deal with more sophisticated paths:
new FirebaseIndex(
new Firebase('URL/index'),
function(pathName) {
return new Firebase('URL/data/'+pathName+'/widget');
}
);
But as your data structure stands in the question, the keys abc
and efg
are completely arbitrary--not linked in any way to your master
data, so I don't see what your function could do other than contain a complete map from master keys to ref paths.
Upvotes: 0
Reputation: 2336
In your example, abc
and efg
should be lists of keys (required as the first parameter in FirebaseIndex
). So instead of refToMaster: "key"
the format should be "key":1
, where the 1 is just a placeholder. Like this:
ref: {
abc: {
"123":1,
"456":1
},
efg: {
"456":1
}
}
Now new FirebaseIndex(ref.child('abc'), master)
will give you both the 123
and the 456
objects in master
, while new FirebaseIndex(ref.child('efg'), master)
will just give you the 456
object.
Upvotes: 1