Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 角火循环非规范化数据_Firebase_Angularfire - Fatal编程技术网

Firebase 角火循环非规范化数据

Firebase 角火循环非规范化数据,firebase,angularfire,Firebase,Angularfire,我有类别和子类别 数据结构如下图所示: 到目前为止,我以这种方式检索数据(仅针对一个类别):[controller] $scope.findOneCategory = function (categoryId) { angularFire(Categories.find(categoryId), $scope, 'category'); } 类别及服务 find: function(categoryId) { return FireRef.categorie

我有类别和子类别

数据结构如下图所示:

到目前为止,我以这种方式检索数据(仅针对一个类别):[controller]

$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>
服务看起来是这样的,我尝试了一些东西,但它错了,不知道应该是什么样子。。。如果有人能帮助我,我将非常高兴

      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...:(
              });
        });

      },

不知道如何将其与AngularView绑定首先,我建议升级到最新的AngularFire版本(目前为0.6),API已经发生了很大的变化,可能更容易完成您尝试的操作

其次,您应该只为每个类别创建一个绑定,子类别ID将自动包含在该数据中,因为它们只是子节点。然后,您需要为子类别名称创建一个单独的绑定,然后您可以查找您的ID

假设您的数据如下所示:

类别:{
-JF1RmYehtF3IoGN9xHG:{
标题:“示例”,
子类别:{
JF1RmYehtF3IoGN239GJ:正确
}
}
},
子类别:{
JF1RmYehtF3IoGN239GJ:{
名称:“示例子类别”,
}
}
您将创建两个绑定,一个用于类别,另一个用于子类别:

函数MyController($scope$firebase){
var ref=新的火基(“https://.firebaseio.com/");
$scope.category=$firebase(参考child(“categories/”+categoryID));
$scope.subcategories=$firebase(参考子类别);
}
最后,在您的视图中,使用从
$scope.category
提取的ID从
$scope.subcategories
获取子类别名称:

  • {{子类别[id].name}

如果这不是类别和子类别,而是帖子和用户,并且您希望通过单个用户显示帖子列表,那么这是正确的解决方案吗?可能会有很多帖子和很多用户。我尝试了许多不同的方法来实现这一点,但似乎找不到正确的方法。如果子类别列表很长,那么将其全部加载可能没有意义。在这种情况下,我会通过为每个子类别创建一个新的$firebase实例(或者可能只是使用常规的firebase API)逐个获取它们。
    $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...:(
              });
        });

      },