0
我正在尝试使用startWith
过滤器,但它不能正确过滤数据,例如P
。让我知道我在这里做错了什么。startWith在AngularJS中使用对象的过滤器
控制器代码 -
变种应用= angular.module( 'filterSample',[]); app.controller( 'filterCtrl',函数($范围){
$scope.data = {
messages: [
{
"id":"111619EEVz",
"name":"Tom 67",
"status":"Pending"
},
{
"id":"115419EEAA",
"name":"Business 34",
"status":"Pending"
},
{
"id":"1B167000WW",
"name":"Jack 78",
"status":"Active",
}
]
}
$scope.startsWith = function (actual, expected) {
var lowerStr = (actual + "").toLowerCase();
return lowerStr.indexOf(expected.toLowerCase()) === 0;
}
});
HTML -
<div ng-controller="filterCtrl">
<input type="text" ng-model="search" />
<ul border="1px" ng-repeat="msg in data.messages | filter:search:startsWith">
<li>{{msg.name}}</li>
</ul>
</div>
工作Plnkr - http://plnkr.co/edit/tByYZ3jpEk7YPpJnMY11?p=preview
编辑1 -
过滤应该是这样的它应该只搜索name
属性而不是搜索整个对象。
THX了很多,它的工作now..btw可以请你对行为:) – Nesh
请注明这作为一个答案解释。 https://docs.angularjs.org/api/ng/filter/filter。检查那里的例子。 – Dhiren