简体   繁体   English

Angular JS如何更改复选框值上的过滤器?

[英]Angular JS how can i switch filters on checkbox values changed?

I have this code, now I want to create two checkboxes one for "emp_nome" and another for "local" when I check either of them I can search my input only for those checked values, help, please 我有这段代码,现在我想创建两个复选框,一个用于“ emp_nome”,另一个用于“ local”,当我检查它们中的任何一个时,我只能在输入中搜索那些选中的值,请帮助

<input type="text" id="myInput" ng-model="search.SN" placeholder="Search for names..">
<div style="overflow-x:auto;">

  <table id="myTable">
    <tr style="border-bottom:1px solid black;" class="header">
      <td>ID</td>
      <td>Nome Entidade</td>
      <td>Ultima Localização</td>
      <td>Categoria</td>
      <td>Nº de Reclamações contra Entidade</td>
      <td>Data da última reclamação</td>
    </tr>

    <tr ng-repeat="x in myData | filter: {emp_nome: search.SN} || filter: {local: search.SNs}" id="removal">
      <td>{{ x.id }}</td>
      <td style="background:rgba(0, 159, 255, 0.24);font-size:17px;"><u>{{ x.emp_nome }}</u></td>
      <td>{{ x.local }}</td>
      <td>{{ x.tipo }}</td>
      <td>
        <center>{{ x.emp_rec }}</center>
      </td>
      <td>
        <center>{{ x.data }}</center>
      </td>
    </tr>

  </table>

  <br><br>

</div>

You can make the filter expression dynamically and manage it in your controller. 您可以动态创建过滤器表达式并在控制器中对其进行管理。 I mean ng-repeat="x in myData | filter: {emp_nome: search.SN}" could be ng-repeat="x in myData | filter: filterObject" 我的意思是ng-repeat="x in myData | filter: {emp_nome: search.SN}"可能是ng-repeat="x in myData | filter: filterObject"

And you could manage to populate this filterObject to have the object you want to use in filter, by using ng-change (in your input text & checkbox) for example 并且您可以通过使用ng-change(在输入文本和复选框中)来填充该filterObject以使您想要在过滤器中使用的对象

example in ng-change may be: ng-change中的示例可能是:

if (checkboxValue === 'local') { //local checked
  $scope.filterObject = {local: $scope.search.SN};
} else if (checkboxValue === 'emp_nome') {//emp_nome checked
  $scope.filterObject = {emp_nome: $scope.search.SN};
} else { //filter by all
  $scope.filterObject = $scope.search.SN;
}

it's just an example, I don't know how you manage it 这只是一个例子,我不知道你如何管理

Official doc about filter: https://docs.angularjs.org/api/ng/filter/filter 有关过滤器的官方文档: https : //docs.angularjs.org/api/ng/filter/filter

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

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