Javascript 使用AngularFire/Firebase查询在视图中创建过滤器
我正在构建一个应用程序,用户在其中输入品尝,这些品尝会显示在几个地方——在用户的个人品尝页面和“最新品尝”样式页面上 在tastings页面上,单击按钮时,会调用一个“basicStatings()”函数,这就是我想要查询数据库的地方,并且视图只更新那些具有“Type:Basic”(也就是Type:advanced)的tastings 在该函数中,我的测试控制台日志正确地输出key()是basic/advanced。我迷失的地方是将那个对象推入范围,这样现在只有那些对象通过ng repeat 最后,我这样做有意义吗?我是以这种方式来处理它的,而不是通过jQuery.click()过滤方法,因为我认为如果我在数据库中有大量数据,这是一种更好的方法 我的数据设置为:Javascript 使用AngularFire/Firebase查询在视图中创建过滤器,javascript,angularjs,firebase,angularfire,Javascript,Angularjs,Firebase,Angularfire,我正在构建一个应用程序,用户在其中输入品尝,这些品尝会显示在几个地方——在用户的个人品尝页面和“最新品尝”样式页面上 在tastings页面上,单击按钮时,会调用一个“basicStatings()”函数,这就是我想要查询数据库的地方,并且视图只更新那些具有“Type:Basic”(也就是Type:advanced)的tastings 在该函数中,我的测试控制台日志正确地输出key()是basic/advanced。我迷失的地方是将那个对象推入范围,这样现在只有那些对象通过ng repeat 最
{
"tastings" : {
"-JlUCGqbLssTeob7weQI" : {
"brewdate" : "2015-03-28T07:07:04.880Z",
"origin" : "Panama",
"overallrating" : 4.5,
"roaster" : "Verve",
"roastname" : "Los Lajones Honey",
"subdate" : 1427526458869,
"thoughts" : "Cup Characteristics: This Honey-Process coffee from Los Lajones is abdundantly juicy and filled with lovely stone fruit notes like Bing cherry and apricot. The body is like a perfectly tempered ganache.",
"type" : "basic",
"user" : "simplelogin:19"
}
},
"simplelogin:19" : {
"date" : 1427086513603,
"email" : "test@test.com",
"regUser" : "simplelogin:19",
"username" : "Tester"
}
}
}
我列出品尝的控制器是:
myApp.controller('TastingsListController',
function($scope, $firebaseArray, $rootScope, $location, Authentication, FIREBASE_URL) {
$scope.$emit('callForAuth'); // Emitter to initiate $onAuth function in Authentication service
var ref = new Firebase(FIREBASE_URL + '/tastings');
var tastingsInfo = $firebaseArray(ref);
$scope.filterBasic = function() {
ref.orderByChild("type").on("child_added", function(tasting) {
console.log(tasting.key() + ' is a ' + tasting.val().type + ' tasting.');
if(tasting.val().type === "basic") {
tastingsInfo.push(tasting);
console.log(tastingsInfo);
}
});
};
});
最后是相关ng repeat和触发功能的按钮:
<md-button class="md-raised md-accent" ng-click="filterBasic()" flex>
Basic
</md-button>
</div>
</md-toolbar>
<md-content class="md-padding">
<div class="basiccontainer" ng-repeat="tasting in tastings | orderBy: 'brewdate'">
用户:
“用户”:{
“simplelogin:18”:{
“日期”:1427062799596,
“电子邮件”:test@test.com",
“regUser”:“simplelogin:18”,
“用户名”:“测试人员”,
“品尝”:{
“-JlUCGqbLssTeob7weQI”:正确,
“”没错,
...
},
},
这个设置将允许我在品酒和它的创建者之间建立一个双向关系。我可以通过相同的提交功能来完成这一切,当用户按下“提交”按钮时,发送品酒的数据,以及使用品酒键转到用户的品酒索引
- 关于我的控制器用户与服务:我现在所做的是尝试在控制器中执行所有操作
- 我应该做的是,从控制器调用“listingsfilter”服务(或我决定调用的任何服务)当我的控制器中的函数通过按键调用时。该服务本身应该执行实际的工作,查询Firebase中的列表,将它们放入某种数组中,并将其发送回控制器,然后控制器将该数据提供给$scope,ng repeat将通过该$scope进行迭代
ref.orderByChild(“type”).equalTo(“basic”);
谢谢,@jacobawenger。我越想越仔细地阅读文档,我觉得我可能完全搞错了。我正在添加一个编辑来解释我的发现。
"tastings" : {
"-JlUCGqbLssTeob7weQI" : {
"brewdate" : "2015-03-28T07:07:04.880Z",
"origin" : "Panama",
"overallrating" : 4.5,
"roaster" : "Verve",
"roastname" : "Los Lajones Honey",
"subdate" : 1427526458869,
"thoughts" : "Cup Characteristics: This Honey-Process coffee from Los Lajones is abdundantly juicy and filled with lovely stone fruit notes like Bing cherry and apricot. The body is like a perfectly tempered ganache.",
"type" : "basic",
"user" : {
"simplelogin:18": true,
},
},
"users" : {
"simplelogin:18" : {
"date" : 1427062799596,
"email" : "test@test.com",
"regUser" : "simplelogin:18",
"username" : "Tester",
"tastings" : {
"-JlUCGqbLssTeob7weQI": true,
"<Tasting 2 Key>": true,
...
},
},