2
我只是试图使用下拉菜单中的输入过滤或搜索相关数据。要求是在下拉列表中选择一个选项,然后单击它应该过滤的按钮或使用角度将相应的数据填充到表格中。我试过我可以直接做,但不是点击事件。请帮我找出解决方案,因为我是一种新角度。这里是我的代码:使用角度单击事件下拉过滤器
我的HTML:
Filter:
<select ng-model="filterItem.store" ng-options="item.name for item in filterOptions.stores">
</select>
<button >search</button>
<table>
<tr>
<th>Name</th>
<th>Price</th>
<th>Rating</th>
</tr>
<tr ng-repeat="item in data | filter:customFilter">
<td ng-click="">
{{item.name}}</td>
<td>{{item.price}}</td>
<td>{{item.rating}}</td>
</tr>
</table>
JS文件:
$scope.customFilter = function (data) {
if (data.rating === $scope.filterItem.store.rating) {
return true;
} else if ($scope.filterItem.store.rating === 6) {
return true;
} else {
return false;
}
};
//The data that is shown
$scope.data = [
{
name: "product1",
price: 198,
rating: 1
},
{
name: "product2",
price: 200,
rating: 5
},
{
name: "product3",
price: 200,
rating: 2
},
{
name: "product4",
price: 10,
rating: 3
},
{
name: "product5",
price: 200,
rating: 3
},
{
name: "product6",
price: 400,
rating: 5
}
Pluker:
http://plnkr.co/edit/RhJic3KYE0Lc42FJ2lOx?p=preview
https://plnkr.co/edit/yfW8nUufnK4euZNVUo6S?p=preview我修改plunker一点我不想seperatley根据它进行排序,你可以建议表ipuput给排序选项或filteroptions这件事@sajeetharan – annie
是什么问题? – Sajeetharan
我更新了我的plunker多一点..先谢谢了 – annie