我想仅使用类别名称过滤结果,但得到错误的结果。 我正在使用离子框架开发移动应用程序并使用卡片视图。
代码:
<input type="search" ng-model="searchme" placeholder="Search by Category">
<div ng-repeat="data in categories.data | filter:searchme">
<div class="row" ng-if="$even">
<div class="col col-50" ng-if="categories.data.indexOf(categories.data[$index])!=-1">
<div class="list card" ng-click="getProducts(categories.data[$index].category_id,categories.data[$index].category_name)">
<div class="item item-image">
<img src="{{categories.image_path}}{{categories.data[$index].category_image}}" style="min-height:250px;max-height:250px;">
</div>
<ion-item class="item" style="text-align:center">{{categories.data[$index].category_name}}</ion-item>
</div>
</div>
<div class="col col-50" ng-if="categories.data.indexOf(categories.data[$index+1])!=-1">
<div class="list card" ng-click="getProducts(categories.data[$index + 1].category_id,categories.data[$index + 1].category_name)">
<div class="item item-image">
<img src="{{categories.image_path}}{{categories.data[$index + 1].category_image}}" style="min-height:250px;max-height:250px;">
</div>
<ion-item class="item" style="text-align:center">{{categories.data[$index + 1].category_name}}</ion-item>
</div>
</div>
</div>
</div>
我的json:
{"status":"1","image_path":"http:\/\/something.com\/asset\/images\/category_image\/","thumb_path":"http:\/\/something.com\/asset\/images\/category_image\/thumb\/","data":[{"category_id":"5","category_name":"BASIC JEANS","brand_id":"44","category_image":"20150914122932_img_0247ddvh.jpg"},{"category_id":"6","category_name":"BASIC JEGGINGS","brand_id":"44","category_image":"20150914122922_img_0262.jpg"},{"category_id":"7","category_name":"PYJAMAS","brand_id":"44","category_image":"20150914122852_img_0305yhjn.jpg"}]}
我在这个json中使用了ng-repeat数据,我想使用类别名称进行过滤。
答案 0 :(得分:1)
尝试更改ng-model =&#34; searchMe&#34; to&#34; searchMe.categoryName&#34;或者您的集合中引用categoryName的属性名称。
请参阅此处的第一个示例https://docs.angularjs.org/api/ng/filter/filter
您似乎也在尝试重复相同的代码块两次。这也导致了问题。
100 %
我在这里做了一个工作的傻瓜http://plnkr.co/edit/busGtyjwJwjDdoBer6HP?p=preview