简体   繁体   中英

Can ng-repeat displays data based on a rule? *filter*

I have two selects (multi-select /picklist).

I need to display clients on both sides, but:

  • The picklist on left, should display only clients that have this field 'consultaNotasDestinadasAutomaticamente' as true in 'cliente' table.

  • The picklist on right, should display only clients that have this field 'consultaNotasDestinadasAutomaticamente' as false in 'cliente' table.

How can I do this?

Here goes my html:

   <div class="form group">
         <label class="control-label col-md-3">Empresas:</label>
         <select id="select1" name="select1" multiple="multiple">
             <option ng-repeat="c in clientes" value="{{c.idCliente}}" ng-click="atribuirUm($index, c)">{{c.razaoSocial}}</option>                            
         </select>
         <label class="control-label col-md-3">Empresas:</label>
         <select ng-model="listaEmpresas" id="select2" name="select2" multiple="multiple">
             <option selected="selected" ng-repeat="c2 in clientes2" value="{{c2.idCliente}}" ng-click="limparUm($index, c2)">{{c2.razaoSocial}}</option>                              
         </select>                               
   </div>

You can use pipe | to pass data to filters

ng-repeat="c in clients | filter:{consultaNotasDestinadasAutomaticamente: true}"

You can actually pipe as many build in and custom filters as you want ie

ng-repeat="c in clients | filter:{consultaNotasDestinadasAutomaticamente: true} | limitTo:4 | json"

Filters documentation: https://docs.angularjs.org/api/ng/filter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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