I have the following JSON:
[{
"IdModulo": 1,
"IdPadre": 0,
"Nombre": "Home",
"Ruta": "menu.home",
}, {
"IdModulo": 2,
"IdPadre": 0,
"Nombre": "Administrador",
"Ruta": "menu.administrador"
}, {
"IdModulo": 3,
"IdPadre": 0,
"Nombre": "Informes",
"Ruta": "menu.informes"
}, {
"IdModulo": 4,
"IdPadre": 2,
"Nombre": "Carga archivo",
"Ruta": "menu.administrador"
}, {
"IdModulo": 5,
"IdPadre": 2,
"Nombre": "Verificación",
"Ruta": "menu.verificacion"
}, {
"IdModulo": 6,
"IdPadre": 2,
"Nombre": "Procesados",
"Ruta": "menu.procesados"
}, {
"IdModulo": 7,
"IdPadre": 2,
"Nombre": "Hyperion",
"Ruta": "menu.hyperion"
}, {
"IdModulo": 10,
"IdPadre": 2,
"Nombre": "Clientes",
"Ruta": "menu.clientes"
}, {
"IdModulo": 8,
"IdPadre": 3,
"Nombre": "Reclasificaciones",
"Ruta": "menu.reclasificacion"
}, {
"IdModulo": 9,
"IdPadre": 3,
"Nombre": "Resumen",
"Ruta": "menu.resumen"
}]
Which I want to filter so that it only generates those elements whose IdPadre = 0
.
I use this code to generate the elements with the condition IdPadre = 0
:
<ul class="nav navbar-nav">
<li ng-repeat="menues in menu | filter: IdPadre = 0" ng-class="getClass('/{{menues.Nombre.toLowerCase()}}')" class="" ng-click="cargarItemsDelMenu(menues.IdModulo)">
<a ui-sref="{{menues.Ruta}}">
<span>{{menues.Nombre.toUpperCase()}}</span>
</a>
</li>
</ul>
But (in addition to the elements that meet the condition) it brings me the "Customers" element - this one shouldn't bring it, because its IdPadre = 2
.
What am I doing wrong and how do I manage to correctly filter the values based on the filter?
Good morning Mauro, you have the following error within
json
what you have:you have a "," after the element
Ruta:"menu.home"
for which you have to eliminate thatCOMA
, now what you have to do is that within the line ofng-repeat
is to do thefilter
in this wayng-repeat="data in datos | filter: { IdPadre: 0 }"
, I hope it works for you if you tell me something.