我正在构建一个用户输入品尝的应用程序,这些品尝会显示在几个地方 - 用户的个人品尝页面和“最新品尝”样式页面。
在品尝页面上,当点击一个按钮时,会调用“basicTastings()”函数,这就是我想要查询数据库的地方,以及只有那些具有“类型:基本”的品牌更新视图的地方“(你也是类型:高级)。
在该函数中,我的测试控制台日志正确输出key()是basic / advanced。我丢失的地方然后将该对象推入范围,以便只有那些对象现在通过ng-repeat。
最后 - 以这种方式做到这一点对我来说是否有意义?我正以这种方式接近它,而不是通过jQuery .click()过滤的想法,因为我认为如果我在数据库中最终获得大量数据,这是一种更好的方法。
我的数据设置为:
{
"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'">
编辑:我在console.log中获取的数据发生在每次“基本”的品尝之后,这是它应该发生的地方,但它包含整个对象数组,当我希望它只包含对象时,然后我想将该对象放入一个数组中,然后我可以使用ng-repeat进行迭代。
编辑2:我认为我正在接近这一切:
我一直在阅读和重新阅读,我想我现在看到我的方法,基本上,Firebase文档正在说不要做的事情:
品尝:
"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,
...
},
},
这个设置将允许我在品尝和它的创建者之间实际建立双向关系。当用户按下“提交”按钮时,我可以通过相同的提交功能完成此操作 - 发送品尝数据,并将品尝的密钥用于用户的品尝索引。