【发布时间】:2014-02-07 16:57:19
【问题描述】:
我有类别和子类别。
数据结构如blog所示:
categories: {
-JF1RmYehtF3IoGN9xHG(categoryId): {
title: "Example",
subcategories: {
JF1RmYehtF3IoGN239GJ(subCategoryId): true
}
到目前为止,我以这种方式检索数据(仅针对一个类别):[控制器]
$scope.findOneCategory = function (categoryId) {
angularFire(Categories.find(categoryId), $scope, 'category');
}
分类服务
find: function(categoryId) {
return FireRef.categories().child('/'+categoryId);
},
这很好用!
但现在我需要检索类别中的子类别列表并将其绑定到范围,我不知道如何...我目前有这个:
观点:
<div ng-init="findSubCategories()">
<li class="list-group-item" ng-repeat="subCategory in subCategories">{{ subCategory.name }}</li>
控制器:
$scope.findSubCategories = function() {
angularFire(Categories.findSubCategories($routeParams.categoryId), $scope, 'subCategories');
}
服务看起来像这样
不知道如何将其与角度视图绑定 findSubCategories: function(categoryId) {
var subCategoriesIdsList = FireRef.categories().child('/'+categoryId).child('subcategories');
subCategoriesIdsList.on("child_added", function(snap) {
FireRef.subcategories().child("/"+snap.name()).once("value", function(snap) {
// Render the comment on the link page.
console.log(snap.val());(i see the object in console but have no idea how to bind it now with the view...:(
});
});
},
【问题讨论】:
标签: firebase angularfire