简体   繁体   English

Angularfire2可观察的concat无法正常工作

[英]Angularfire2 Observable concat not working

This is what my data looks like: 这是我的数据:

{
  "Category" : {
    "-KVuXp30tdhR1CqmCb_X" : {
      "name" : "Category1",
      "parentCategoryId" : ""
  },
    "-KVuY0CjGePvUo2qVcGb" : {
      "name" : "Category2",
      "parentCategoryId" : ""
  },
    "-KW9U76wJg-4hgnMUvu2" : {
      "name" : "Category1sub1",
      "parentCategoryId" : "-KVuXp30tdhR1CqmCb_X"
  },
    "-KYODOJXjqnRMkVSsIFs" : {
      "name" : "Category2Sub1",
      "parentCategoryId" : "-KVuY0CjGePvUo2qVcGb"
  },
    "-KYOKdbX22UCeU2EZcYQ" : {
      "name" : "Category1Sub3",
      "parentCategoryId" : "-KVuXp30tdhR1CqmCb_X"
  },
    "-KYOM3dV9pX0Isx-7V5C" : {
      "name" : "Category2Sub2",
      "parentCategoryId" : "-KVuY0CjGePvUo2qVcGb"
  }
 }
}

I want to list under main categories and sub categories. 我想在主要类别和子类别下列出。

  • Category1 类别1
  • Category2 类别2
  • Category1 >> Category1sub1 类别1 >>类别1子1
  • Category2 >> Category2Sub1 Category2 >> Category2Sub1
  • Category1 >> Category1Sub3 类别1 >>类别1类别3
  • Category2 >> Category2Sub2 类别2 >>类别2

The sample code here (plunker) . 这里的示例代码(plunker)

What am I doing wrong. 我究竟做错了什么。 How do i do it. 我该怎么做。

Thanks. 谢谢。

AngularFire 's list method returns Observabel that never ends so there is no point in using it in concat . AngularFire的list方法返回的Observabel永不结束,因此在concat中使用它毫无意义。 If you want to get only first value you should use take . 如果只想获取第一个值,则应使用take

There is no db property on your service, hence 您的服务上没有db属性,因此

this.db.object

will throw an error (you didn't see an error because that code hadn't been executed). 会抛出一个错误(您没有看到错误,因为该代码尚未执行)。

Look at this plunker and ask if something is not clear. 看一下这个矮人 ,问是否不清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM