我想通过" City"过滤我的Firebase数据。但是我没有得到JSON作为回报......当我导入JSON时,我的结构是这样的......
[
{
"ID": 1,
"Name": "Goroka Airport",
"City": "Goroka"
},
{
"ID": 2,
"Name": "Madang Airport",
"City": "Madang"
}
]
我的Javascript如下...不返回任何内容
var myFirebaseRef = new Firebase("https://URL-apps.firebaseio.com/airports");
myFirebaseRef.orderByChild('City').equalTo('Goroka').on("value",function(snapshot) {
var data = snapshot.forEach(function(child) {
console.log(JSON.stringify(child.val()));
});
});
Firebase数据库布局(折叠) - 每个机场都是"机场" 0..1..etc
Firebase数据库布局(扩展)
答案 0 :(得分:0)
你的myFirebaseRef必须是这样的:
var myFirebaseRef = new Firebase("https://URL-apps.firebaseio.com/airports").database().ref();
答案 1 :(得分:0)
SDK使用1.0,上面的Franks代码使用FB JS Client SDK 4.0
var config = {
databaseURL: "https://URL-apps.firebaseio.com/",
};
firebase.initializeApp(config);
var ref = firebase.database().ref("/airports");
ref.orderByChild('City').equalTo('Goroka').on("value",function(snapshot) {
snapshot.forEach(function(child) {
console.log(JSON.stringify(child.val()));
});
});