I have an array that looks like this:
我有一个看起来像这样的数组:
validZipCodes = [
"84606",
"84605",
"84601"
]
I'm querying some data like this:
我正在查询这样的数据:
var Jobs = firebase.child('Jobs');
I tried this:
我试过这个:
var Jobs = firebase.child('Jobs').orderByChild('ZipCode').equalTo($scope.validZipCodes);
But it returned an error that it was an invalid data-type, is there anyway to say something like:
但它返回了一个错误,它是一个无效的数据类型,无论如何要说:
var Jobs = firebase.child('Jobs').orderByChild('ZipCode').inArray($scope.validZipCodes);
Or something like that.
或类似的东西。
Note that this is an array comparison & not querying text in an object.
请注意,这是一个数组比较,而不是查询对象中的文本。
2 个解决方案
#1
Here is how I eventually did it:
这是我最终做到的方式:
With the foreach command you can easily manipulate data and then push it into an array to re-create a collection of data however you need it.
使用foreach命令,您可以轻松地操作数据,然后将其推送到数组中,以便在需要时重新创建数据集合。
$scope.validZipCodes = [];
$scope.validContractorJobs = [];
var Jobs = firebase.child('Jobs');
contractorJobs.on('value', function(snap) {
snap.forEach(function(job) {
angular.forEach($scope.validZipCodes, function(value, key) {
if(job.val().ZipCode == value) {
$scope.validContractorJobs.push(job.val());
}
});
});
});
#2
The Firebase .equalTo()
documentation states that the value
argument should be one of the following types: String
, Number
, Null
, or Boolean
.
Firebase .equalTo()文档声明value参数应为以下类型之一:String,Number,Null或Boolean。
-
You are getting an
invalid data-type
error because you are not passing one of these types.您收到的数据类型错误无效,因为您没有传递其中一种类型。
-
There is no method like
.inArray()
(i.e. querying for equalTo multiple values).没有类似.inArray()的方法(即查询equalTo多个值)。
You can review all of the Firebase Query Methods in the Query documentation, which also suggests:
您可以查看查询文档中的所有Firebase查询方法,该文档还建议:
Read our documentation on ordering and querying data for more information and examples.
阅读有关订购和查询数据的文档,以获取更多信息和示例。
#1
Here is how I eventually did it:
这是我最终做到的方式:
With the foreach command you can easily manipulate data and then push it into an array to re-create a collection of data however you need it.
使用foreach命令,您可以轻松地操作数据,然后将其推送到数组中,以便在需要时重新创建数据集合。
$scope.validZipCodes = [];
$scope.validContractorJobs = [];
var Jobs = firebase.child('Jobs');
contractorJobs.on('value', function(snap) {
snap.forEach(function(job) {
angular.forEach($scope.validZipCodes, function(value, key) {
if(job.val().ZipCode == value) {
$scope.validContractorJobs.push(job.val());
}
});
});
});
#2
The Firebase .equalTo()
documentation states that the value
argument should be one of the following types: String
, Number
, Null
, or Boolean
.
Firebase .equalTo()文档声明value参数应为以下类型之一:String,Number,Null或Boolean。
-
You are getting an
invalid data-type
error because you are not passing one of these types.您收到的数据类型错误无效,因为您没有传递其中一种类型。
-
There is no method like
.inArray()
(i.e. querying for equalTo multiple values).没有类似.inArray()的方法(即查询equalTo多个值)。
You can review all of the Firebase Query Methods in the Query documentation, which also suggests:
您可以查看查询文档中的所有Firebase查询方法,该文档还建议:
Read our documentation on ordering and querying data for more information and examples.
阅读有关订购和查询数据的文档,以获取更多信息和示例。