关于Angularfire的Foreach - 避免迭代方法?

时间:2014-04-23 10:27:09

标签: angularjs firebase angularfire

我正在从firebase中检索一些数据,这给了我一个看起来像这样的对象:

$add: function (item) {
$auth: function (token) {
$bind: function (scope, name, defaultFn) {
$child: function (key) {
$getIndex: function () {
$getRef: function () {
$id: "tasks"
$off: function (type, callback) {
$on: function (type, callback) {
$remove: function (key) {
$save: function (key) {
$set: function (newValue) {
$transaction: function (updateFn, applyLocally) {
$update: function (newValue) {
-JLCrhLLGqp-OZN-9toC: true
-JLCrkqFxxxaV6eG8lrb: true
__proto__: Object

我需要遍历所有看起来像“-JLCrhLLGqp-OZN-9toC”的键。

我的问题是我怎么做到最好?我可以以某种方式删除$方法吗?

使用ng-repeat在html中执行此操作很容易,这似乎可以找出要忽略的部分。但我无法弄清楚如何在控制器上做到这一点?

1 个答案:

答案 0 :(得分:3)

在迭代属性时可以使用角度isFunction函数:

angular.forEach( $scope.firebaseObject, function(value, key){
  if( !angular.isFunction(value)){
    alert(key + ' is not a function');
  }
});

Fiddle