在AngularJS中通过另一个Firebase对象过滤Firebase列表
-
21-12-2019 - |
题
所以我有一个大的firebase列表,我想使用我绑定的另一个firebase对象来过滤。如果我没有将我的“搜索”对象绑定到FileBase IT,它就会好的,但是当我绑定到Firebase时,它会返回零结果。
我的控制器:
.controller('TestResultsCtrl', ['$scope', 'syncData', '$routeParams', '$firebase', '$filter', function($scope, syncData, $routeParams, $firebase, $filter) {
$scope.id = $routeParams.id;
syncData('tests/' + $routeParams.id).$bind($scope, 'test');
syncData('tests/' + $routeParams.id + '/specs').$bind($scope, 'search');
syncData('diagnoses').$bind($scope, 'all_diagnoses');
}])
.
我的视图:
<a href="" ng-repeat="diagnoses in all_diagnoses | orderByPriority | filter:search" class="list-group-item">{{diagnoses.title}}</a>
.
样本'搜索'对象:
{
"constant": true,
"intermittent": true,
"localized": true,
"referred": false,
"region": "hip"
}
.
“诊断”Firebase对象/列表的样本:
{
"constant": true,
"intermittent": true,
"localized": true,
"referred": false,
"region": "hip",
"title": "Hip Osteoarthritis"
},
{
"constant": true,
"intermittent": false,
"localized": false,
"referred": true,
"region": "neck",
"title": "Whiplash"
}
.
如何将其正确过滤?
......并提前谢谢!
解决方案
问题可能是从$ bind返回的对象包含几种方法,该方法正在尝试过滤。
尝试这样的东西...
syncData('tests/' + $routeParams.id + '/specs').$bind($scope, 'searchDirty');
$scope.$watch('searchDirty', function (search) {
$scope.search = angular.fromJson(angular.toJson(search));
});
.
这将删除任何$方法/值并返回数据的原始值。
不隶属于 StackOverflow