与列表视图不兼容的getValue返回对象

时间:2019-01-24 19:22:44

标签: firebase vue.js nativescript

我正在使用nativescript-plugin-firebase插件和以下功能从firebase获取数据并将其显示在listview组件中。但是,它正在下载一个对象,我认为listview需要一个数组。我看了网上的每个论坛帖子,却想不出如何正确地将此对象重新格式化为listview所需的格式。使用vuefire for web,这非常容易,但是我无法通过此组件来解决。任何帮助将非常感激。

我尝试了以下方法:

  • result.json(),它似乎不适用于本机脚本
  • JSON.parse(result)
  • for循环推送到数组的for循环的不同形式,这是可行的,但我无法弄清楚如何为listview正确格式化数组。
  • Object.keys(result).map(item => result [item])
  • 除了getValue方法之外,我还尝试了查询方法,但也没有运气。
//Here is my listview component:

<ListView class="list-group" for="getWod in getWods" @itemTap="onItemTap"
                    style="height:1250px">
                    <v-template>
                        <FlexboxLayout flexDirection="row" class="list-group-item">
                            <Label :text="getWod.workoutType" class="list-group-item-heading"
                                style="width: 60%" />
                        </FlexboxLayout>
                    </v-template>
                </ListView>


//Here is my call to the API (when I call this function, I set the returned value to "this.getWods") 

fetchRequestForGettingData(currentDate1) 
{ return firebase.getValue('/wods') 
.then(result => { return result; }) 
.catch(error => console.log("Error: " + error)); }


//Here is what is returned by my function:
key: 'wods', value: 
{ '-LWcIjtZGo-arGiWjWJd': 
{ weight: 'testing123', workoutType: 'testing123', time: 'testing123', edit: false, reps: 'testing123', date: '01-02-2019', timeCap: 'testing123', workout: 'testing123', description: 'testing123', name: 'testing123' }, 
'-LWjCMG-jNDnEudppl9J': 
{ weight: 'testing123', workoutType: 'testing123', time: 'testing123', edit: false, reps: 'testing12332', date: '02-01-2019', timeCap: 'testing123', workout: '-LWU4DWJWVJxWkDSZYw9', description: 'testing123', name: 'testing123' }, 
'-LWjEtBwIJDPHK43hVjK': 
{ weight: 'testing123', workoutType: 'testing123', time: 'testing123', edit: false, reps: 'testing12332', date: '20-01-2019', timeCap: 'testing123', workout: '-LWc289<…> 

我的预期输出是与listview组件兼容的对象/数组。

0 个答案:

没有答案