【问题标题】:How to start filtering only when the length of querytext is equal to 2仅当querytext的长度等于2时如何开始过滤
【发布时间】:2014-01-27 12:29:51
【问题描述】:

只有在查询文本的长度等于 2 时,我才能开始过滤?

我有这段代码,但我不知道如何仅在 querytext.length >=2 时开始过滤

<input type="search" ng-model="querytext">
<ul>
    <li ng-repeat="value in filteredList | filter:querytext>{{value.Name}}</li>
</ul>
$scope.filteredList =[{Id:1,Name:"Soul"},{Id:2,Name:"Croft"}];

【问题讨论】:

    标签: angularjs angularjs-filter


    【解决方案1】:

    ng-minlength="2" 添加到&lt;input&gt; 元素。

    <input type="search" ng-model="querytext" ng-minlength="2" />
    <!--                                      ^^^^^^^^^^^^^^^^ -->
    

    【讨论】:

      【解决方案2】:

      正如@Daiwei 所建议的,这就是我所做的:

      <input type="search" ng-model="querytext" ng-minlength="2">
      <ul>
          <li ng-repeat="value in filteredList | filter:querytext>{{value.Name}}</li>
      </ul>
      

      它有效!谢谢!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-03-26
        • 1970-01-01
        • 2022-01-14
        • 1970-01-01
        • 2020-08-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多