1

为了

$scope.phones = [ 

    {"name": "Nexus S",
 "snippet": "Fast just got faster with Nexus S."},
{"name": "Motorola XOOM™ with Wi-Fi",
 "snippet": "The Next, Next Generation tablet."},
{"name": "MOTOROLA XOOM™",
 "snippet": "The Next, Next Generation tablet."}

];

html(玉)

p Search <input ng-model="query">

下面应用了“过滤器| 查询'到整个'电话'。您如何将查询仅应用于电话中的字段?

喜欢(phones.snippet| 过滤器:查询)

li(ng-repeat="phone in phones|filter:query")
4

1 回答 1

0

您可以自己定义过滤器:

function MainController($scope) {
$scope.searchparam = "Nexus";

$scope.query = function(item) {
    return item.name.contains($scope.searchparam);
};
$scope.phones = 
    [ 
        {"name": "Nexus S", "snippet": "Fast just got faster with Nexus S."},
        {"name": "Motorola XOOM™ with Wi-Fi", "snippet": "The Next, Next Generation tablet."},
        {"name": "MOTOROLA XOOM™", "snippet": "The Next, Next Generation tablet."}
    ];}

演示

于 2013-09-11T09:30:36.690 回答