简体   繁体   English

ng-repeat隐藏具有空对象的行

[英]ng-repeat hide rows with empty object

I have a table where I am repeating over an array of objects. 我有一张桌子,在上面重复一组对象。 Within the object, there is a nested object, like so: 在对象内,有一个嵌套对象,如下所示:

[
    {"Object1": 
         {"Sub_obj" : {}
         }
     },

    {"Object2": 
         {"Sub_obj" : 
               {"Name" : "Jane"}
         }
     }
]

I want to ng-hide the table row where "Sub_obj" is empty. 我想ng-hide "Sub_obj"为空的表行。 How can I achieve this? 我该如何实现? I tried ng-hide=!Sub_obj , but that doesn't work. 我尝试了ng-hide=!Sub_obj ,但这不起作用。

Make a simple function that checks the length of the keys in object: 创建一个简单的函数来检查对象中键的长度:

$scope.isEmptyObject(obj){
  return !angular.isObject(obj) || !Object.keys(obj).length
}

view 视图

ng-hide="isEmptyObject(item.Sub_obj)"

ng-hide="Sub_obj.Name == null ; ng-hide =“ Sub_obj.Name == null;

OR ng-hide="Sub_obj.Name == "" 或ng-hide =“ Sub_obj.Name ==”“

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

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