Filter in ng-repeat does not work as expected

1

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 me those elements whose IdPadre = 0 .

I use this code to generate the elements with 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 fulfill the condition) brings me the element "Clients" - this one should not bring it, because its IdPadre = 2 .

What am I doing wrong and how do I successfully filter the values according to the filter?

    
asked by Mauricio Arias Olave 05.03.2018 в 22:15
source

1 answer

3

Good morning mauro, you have the following error within json you have,

{
    "IdModulo": 1,
    "IdPadre": 0,
    "Nombre": "Home",
    "Ruta": "menu.home",
}

you have a "," after the Ruta:"menu.home" element so you have to eliminate that COMA , now what you have to do is that within the line of ng-repeat is to make the filter in this way ng-repeat="data in datos | filter: { IdPadre: 0 }" , I hope it works for you if you tell me something.

    
answered by 05.03.2018 / 22:29
source