如何将 Firebase 服务返回的对象打印为数组(到控制台) [英] How to print object returned by Firebase service as array (to the console)

查看:33
本文介绍了如何将 Firebase 服务返回的对象打印为数组(到控制台)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Angular + Firebase 堆栈.

I am using Angular + Firebase stack.

我想转换 Firebase 返回的对象:

I would like to convert object returned by Firebase:

进入数组,以便它可以像这样在控制台中打印:

into the array so it can be printed in the console like this:

 [ {object}, {object}, {object}, {object}, {Object} ];

我知道如何在模板中使用orderByPriority"过滤器,但我不知道如何在控制器中使用它?

I know how to use "orderByPriority" filter in template but I don't know how to use it inside controller?

推荐答案

如果要将返回的对象数组打印到控制台,则需要应用 orderByPriority 过滤器(正如您已经发现的) 并使用 $watchCollection 来观察变化(因为数据是 asynchronously 返回的):

If you want to print an array of returned objects to the console, you need to apply orderByPriority filter (as you already found out) and use $watchCollection to watch for changes (as data are returned asynchronously):

    $scope.$watchCollection('messages', function() {
      console.log(orderByPriorityFilter($scope.messages));   
    });  

您可以在这个 Plunker 中查看工作解决方案.

You can check out the working solution in this Plunker.

这篇关于如何将 Firebase 服务返回的对象打印为数组(到控制台)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆