AngularJS搜索过滤器,嵌套数组包含所有类似的“键”。
请查看pen,它会详细说明。
我在下面粘贴了数据集,我将可搜索的文本作为“值”。我可以搜索“产品项目”。现在我想按每个字段搜索数据。 即。
数据格式如下:
$scope.dataset = {"items": [
{"itemid": "12345","unitqty": 1,"itemdescription": "Cool Product","favorite":true,"attributegroups": [[{"type": "itemID","title": "Product Item","value": "12345","action": "viewitem"},{"type": "width","title": "Width","value": "1in","action": ""},{"type": "height","title": "Height","value": "2in","action": ""}],[{"type": "color","title": "Color","value": "Mauve","action": ""},{"type": "weight","title": "Weight","value": "20lb Bond","action": ""},{"type": "window","title": "Window","value": "none","action": ""}],[{"type": "detail","title": "Detail","value": "Value","action": ""},{"type": "detail","title": "Detail","value": "Value","action": ""},{"type": "detail","title": "Detail","value": "Value","action": ""}]]},
{"itemid": "12355","unitqty": 1,"itemdescription": "Cool Product","attributegroups": [[{"type": "itemID","title": "Product Item","value": "12355","action": "viewitem"},{"type": "width","title": "Width","value": "1in","action": ""},{"type": "height","title": "Height","value": "2in","action": ""}],[{"type": "color","title": "Color","value": "Mauve","action": ""},{"type": "weight","title": "Weight","value": "20lb Bond","action": ""},{"type": "window","title": "Window","value": "none","action": ""}],[{"type": "detail","title": "Detail","value": "Value","action": ""},{"type": "detail","title": "Detail","value": "Value","action": ""},{"type": "detail","title": "Detail","value": "Value","action": ""}]]},
{"itemid": "12366","unitqty": 1,"itemdescription": "Cool Product","favorite":true,"attributegroups": [[{"type": "itemID","title": "Product Item","value": "12366","action": "viewitem"},{"type": "width","title": "Width","value": "1in","action": ""},{"type": "height","title": "Height","value": "2in","action": ""}],[{"type": "color","title": "Color","value": "Mauve","action": ""},{"type": "weight","title": "Weight","value": "20lb Bond","action": ""},{"type": "window","title": "Window","value": "none","action": ""}],[{"type": "detail","title": "Detail","value": "Value","action": ""},{"type": "detail","title": "Detail","value": "Value","action": ""},{"type": "detail","title": "Detail","value": "Value","action": ""}]]}
]};
});
答案 0 :(得分:0)
如果你看笔,你的输入字段有一个ng-model,<input type="text" placeholder="Item Number" ng-model="attribute.value"/>
你需要为其他字段放置ng-model,就像宽度,高度等一样。
以下是一个示例:
<input ng-model="search.name">
<input ng-model="search.phone">
<input ng-model="search.secret">
<tr ng-repeat="student in class | filter:{name: search.name, phone: search.phone}">
以下是与您合作的方式。
<input type="text" placeholder="Width" ng-model="attribute.width"/>
<input type="text" placeholder="Height" ng-model="attribute.height"/>
<div ng-repeat="item in dataset.items | filter : {attributegroups : {value : attribute.value, width: attribute:width, height: attribute.height}}" class="items">