【问题标题】:ng-repeat filter doesn't apply correctlyng-repeat 过滤器无法正确应用
【发布时间】:2014-10-21 13:37:09
【问题描述】:

我有以下代码:

Titre: <input ng-model="rechercheTitre">
Organisateur: <input ng-model="rechercheOrganisateur">
....
<li ng-repeat="resultats in resultatsJSON.results | filter:rechercheTitre"> 
    <span ng-bind-html="resultats.tra_title | highlight:rechercheTitre"></span>
    Organisateur(s) : {{resultOrganisateurs}}
</li>

我的结果显示正确,但 ng-repeat 中的过滤器应用于 rechercheTitre 和 rechercheOrganisateur。我只希望将过滤器应用于 rechercheTitre。我该怎么做?

【问题讨论】:

    标签: angularjs filter ng-repeat


    【解决方案1】:

    在这种情况下你应该使用object notation:

    ng-repeat="resultats in resultatsJSON.results | filter:{rechercheTitre: rechercheTitre}"
    

    您在哪里定义必须过滤哪些属性(在本例中为 rechercheTitre)数组元素。

    【讨论】:

      【解决方案2】:

      我试过了:

      filter:{rechercheTitre:rechercheTitre} 
      

      控制台没有错误,但是当我在我的 rechercheTitre 输入上输入一个字母时,所有结果都被隐藏了。 我也测试过:

      filter:{rechercheTitre:resultats.tra_title} 
      

      控制台中没有错误,但在这种情况下,所有结果都会始终显示。

      如果有帮助,下面是我的 json 文件的制作方式:

      {
        "count": 90,
        "results": [
        {
            "tra_speakers": "Jack"
            "tra_title": "test titre",
        }, ....
      

      【讨论】:

        【解决方案3】:

        找到解决办法。

        正确答案是:

        filter:{tra_type:rechercheType.tra_type}
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-04-02
          相关资源
          最近更新 更多