简体   繁体   English

如何从Firebase访问项目对象数组

[英]How to access items Array of Objects from Firebase

There is probably a similar question like this, but I have been trying to figure it out myself for an hour and tried to look at similar questions. 可能存在类似的类似问题,但是我一个小时以来一直在尝试自己解决问题,并试图研究类似的问题。 I probably just lack the proper phrase to look up for what I'm experiencing here. 我可能只是缺少适当的短语来查找我在这里遇到的情况。

I have a pretty standard firebase / vue.js application, its actually just a training project I am trying to refactor to use Vuex, http vue resource calls and Firebase for practice. 我有一个非常标准的firebase / vue.js应用程序,它实际上只是一个培训项目,我试图将其重构为使用Vuex,http vue资源调用和Firebase进行练习。 Attached is a picture of how my data is stored in firebase. 附件是我的数据如何存储在firebase中的图片。

Firebase设置

When I do v-for="stock in getStocks" vue.js is able to iterate through my array just fine. 当我在getStocks中执行v-for =“ stock”时,vue.js可以遍历我的数组。 However, when I call my getter and want to just use it in javascript code, I can't actually get at my objects properties. 但是,当我调用getter并只想在javascript代码中使用它时,我实际上无法获取我的objects属性。 It's like there is a layer between the array and the values. 就像数组和值之间有一层。

Attached is how it looks when I do console.log(this.getStocks). 附件是我执行console.log(this.getStocks)时的外观。 getStocks is just a basic vuex getter that returns state.stocks. getStocks只是返回state.stocks的基本vuex getter。

getter返回的控制台日志

This is probably a simple concept I am just not aware of. 我可能不知道这是一个简单的概念。 Hoping someone can point me in the right direction. 希望有人可以指出正确的方向。

My problem is basically, I can't just do like const stocks = this.getStocks; 我的问题基本上是,我不能像const stocks = this.getStocks;那样做。 and then console.log(stocks[0].ticker). 然后是console.log(stocks [0] .ticker)。 Thats where I'm stuck. 那就是我卡住的地方。

I suspect my problem wasn't with the array but with looping through it. 我怀疑我的问题不是数组,而是遍历数组。 It seems to be something to do with trying to do for (var stock in stocks). 这似乎与尝试做(股票中的各种股票)有关。 Doing the plain old for (var i = 0, l = stocks.length; i < l; i++) {... loop style worked. 对(var i = 0,l = stocks.length; i <l; i ++){...循环样式有效。

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

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