角度过滤

时间:2015-06-09 12:11:07

标签: javascript angularjs filter

我有一个表格,分为如下部分:

education: {faculty: "", high_school: ""}
experience: {experience_1: "", experience_2: "", experience_3: ""}
personalInfo: {id: "", type: "", email: "", password: "", password_new: "", first_name: "", last_name: "",…}
skills: {skill_1: "", skill_2: ""}

所有输入都以ngRepeat显示。

 <div ng-repeat="(key, val) in user" >
    <div ng-repeat="(k,v) in val | filter:filterBySection" class="formParameter" >

        <span class="param_label">
            {{k}}:
        </span>

     <span e-class="form-control " class="formParameterValue" editable-text="user.{{key}}.{{k}}" e-name="{{k}}">{{v}}</span>
    </div>   
</div>

如何实现仅显示所选部分的过滤器。例如:如果我按下教育按钮,则只显示教师&#39;和&#39;高中&#39;

<li ng-repeat="(a,b) in user" ng-click="filterBySection = ?:{{a}}" ng-model="filterBySection"><a href="#">{{doc_param}}</a></li>

请提供建议。

2 个答案:

答案 0 :(得分:0)

您可以通过使用按钮设置特定变量来显示不同的div容器,在本例中为&#34; tab&#34;。然后,通过测试&#34; tab&#34;的值,只显示带有相应制表符值的dif。与ng-show。

// Links or buttons
<a href ng-click="tab = 1"> Description</a>
<a href ng-click="tab = 2"> Specifications</a>

// DIVS
<div class ="panel" ng-show="tab === 1">
   <h4>Description</h4>
   <p>{{product.description}}</p>
</div>
<div class ="panel" ng-show="tab === 2">
   <h4>Specifications</h4>
   <p>{{product.specification}}</p>
</div>

答案 1 :(得分:0)

我不会使用内置过滤器模块,而是创建一个自定义过滤器,返回一个布尔值,指示是否应该显示该项目(使用$news-div)。

继续让ng-show设置filterBySection模型。

<li>div更改为:

ng-repeat

然后在<div ng-repeat="(k,v) in val" ng-show="k | filterSelection:filterBySection" class="formParameter" > 对象上添加如下过滤器:

angular.module
相关问题