【问题标题】:Need ng-repeat filter to ignore any hyperlink string values when filtering view过滤视图时需要 ng-repeat 过滤器以忽略任何超链接字符串值
【发布时间】:2015-11-11 19:12:13
【问题描述】:

我试图过滤包含在超链接中的多个项目标题的 ng-repeat 视图,但我得到了基于标题和 URL 字符串值的结果。

如何将过滤器限制为仅包含标题的文本并忽略 URL 中的正数?例如。如果我搜索“电子邮件”,我会得到标题或正文中包含“电子邮件”的项目的结果,但也会得到 URL 字符串中包含“电子邮件”的结果。

<a href="http://google.com?q=email">Search Google for email</a><p>Blah blah blah</p>

非常感谢任何帮助!

<div ng-app="Home">
<div ng-controller="Details">
    <div class="row">
        <div class="col-xs-12 col-sm-5 col-md-4 col-lg-4">
            <div class="searchBox">
                <input type="search" ng-model="search"/>
            </div>
        </div>
    </div>
        <div class="col-xs-12 col-sm-6 col-md-4 col-lg-4" ng-repeat="SectionItem in Sections" ng-init="filterResult=[]" ng-hide="filterResult[$parent.$index].length <= 0">
            <div class="panel panel-default">
                <div class="panel-body">

                    <div>
                        <h1>{{SectionItem.Title}}</h1>
                    </div>

                    <div>
                        <!-- BEGIN: items belonging to this section -->                         
                        <table class="table table-condensed table-hover">
                            <tr ng-repeat="item in (filterResult[$parent.$index] = (SectionItems | filter:search | filterByMatchingSection:SectionItem.Title)) ">
                                <td>

                                    <div class="container-fluid">
                                        <div class="row">
                                            <div class="col-sm-12" ng-show="item.Title != null">
                                                <a href="{{item.URL}}">{{item.Title}}</a>
                                                <p>
                                                    {{item.TextBody}}
                                                </p>
                                            </div>
                                        </div>
                                    </div>

                                </td>
                            </tr>
                        </table>
                        <!-- END: items belonging to this section -->
                    </div>

                </div>
            </div>
        </div>
    </div>

</div>  

【问题讨论】:

    标签: javascript angularjs filter ng-repeat


    【解决方案1】:

    这应该可以解决问题

    <input type="search" ng-model="search.Title"/>
    

    【讨论】:

      【解决方案2】:

      根据docs,您可以使用模式对象表达式。对于您的情况,这应该有效:

      ... | filter: { title: search } | ...
      

      这将仅在 title 属性中搜索。

      【讨论】:

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