如何循环遍历我的 Firebase 快照以使用 v-for 列出?

How to loop over my Firebase snapshot to list using v-for?

我想从我的 Firebase 数据库中过滤数据,只列出 authUser 等于当前登录用户的作业。

我使用了.orderByChild方法来过滤数据。但是,我不明白为什么循环进入快照以获取单个值不起作用。

这是我的组件,我想在其中列出所有符合此条件的职位。

Jobs Component code

此外,如果我console.log预览接收到的数据,它看起来像这样。这样不行吗?

Console output

这是我的 Firebase 数据结构。没有定义明确的规则。

enter image description here

我对 Vuejs 还很陌生。

添加 self.myJobs = snapshot.val() 后,我的控制台输出如下所示:

updated console output

你能试试这样的吗?

let vm = this //define this variable before the cursor definition

// comment the snapshot.forEach section and replace by

vm.myJobs = snapshot.val() //or any variable containing the jobs

添加到@Farouk Mekkaoui 的回答中,在你的 v-for 中你需要这样的东西:

  <li v-for="job in myJobs">
    {{ job.name }} //any or whatever property you want to access...
  </li>

编辑: 不要注释掉 snapshot.foreach loop.

snapshot.foreach(function(data){
  this.myJobs.push(data.val().name)
}