在针对此主题搜索大量帖子后,似乎Firebase无法将数据存储为数组:https://www.firebase.com/docs/web/guide/understanding-data.html
在过滤方面真的很痛苦。我正在创建一个简单的全球搜索服务:
servicesModule.factory('globalFilter', function() {
return {
searchText: []
};
});
使用典型的全站点搜索框:
<form>
<div class="input-field">
<input id="search" type="search" required ng-model="globalFilter.searchText">
<label for="search"><i class="material-icons medium">search</i></label>
</div>
</form>
这将根据当前视图过滤结果,因此,如果您在家中,您将拥有一个带有ng-repeat指令的视图:
<div class="col s12 m6" id="postItems" ng-repeat="article in articles | filter: globalFilter.search">
然而它会抛出相同的错误:Error: [filter:notarray] Expected array but received:
并且我不能在globalFilter.searchText的情况下使用firebaseArray,因为该值为空。我试图在空“[]
”中添加其空值,但它仍然不会被作为数组拾取。
当然其他人一定有这样的问题,如果是这样的话,如何创建“Firebase / Angular-friendly”搜索过滤器?
更新:我发现了thread
但它仍然不适合我,我相信这是因为文章是firebasearray而不是对象。所以我收到以下错误:
Error: [$injector:unpr] Unknown provider: orderByPriorityFilterProvider
Ť
文章控制器
controllersModule.controller('BlogCtrl', ["$scope", "dataService", "globalFilter", function($scope, dataService, globalFilter) {
dataService.query(function(articles){
$scope.myArticles = articles;
})
}]);
Firebase查询服务:
servicesModule.factory("dataService", function($resource){
return $resource("https://<SOURCE>.firebaseio.com/articles.json", {
id: "@id"
},
{
update: {
method: "PUT"
},
query: {
method: 'GET'}
});
});
JSON FORMAT
Articles.json
article {
1: {
Title: "Are you suggesting that coconuts migrate?",
Body: "<p>Go and boil your bottoms, sons of a silly person! I blow my nose at you, so-called Ah-thoor Keeng, you and all your silly English K-n-n-n-n-n-n-n-niggits! She looks like one.</p><p>Where'd you get the coconuts? The swallow may fly south with the sun, and the house martin or the plover may seek warmer climes in winter, yet these are not strangers to our land. It's only a model. But you are dressed as one…</p>",
Intro: "You don't frighten us, English pig-dogs!",
Tags: [{text: "coconuts"},{text: "migraine"},{text: "headaches"}]
}
}