[英]angularjs filter | do not filter all object properties
一個簡單的`angularjs'過濾器實現如下:
<!DOCTYPE html>
<html ng-app="app">
<head>
<title>angularjs</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="js/app.js"></script>
</head>
<body>
<input type="text" name="query" value="" placeholder="query" ng-model="q">
<ol ng-controller="ItemsController">
<li ng-repeat="item in items | filter: q">
{{item.name}}
</li>
</ol>
</body>
<script type="text/javascript">
'use strict';
(function() {
var app = angular.module('app', []);
app.value('items', [
{name: 'Item 3', position: 3, color: 'red', price: 2.75},
{name: 'Item 1', position: 1, color: 'red', price: 0.92},
{name: 'Item 4', position: 4, color: 'blue', price: 3.09},
{name: 'Item 2', position: 2, color: 'red', price: 1.95}
]);
app.controller('ItemsController', function($scope, items) {
$scope.items = items;
});
})();
</script>
</html>
當我在輸入框中搜索時,它會搜索items
數組中對象的所有屬性,包括position
和price
即使只重復name
屬性。 即如果我搜索2,則返回item 1
, item 2
和item 3
。 但我只想要第2項。如何將搜索鎖定為僅對象的可見屬性?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.