[英]startWith filter with object in AngularJS
我正在嘗試使用startWith
過濾器,但是它不能正確過濾數據,例如P
。 讓我知道我在這里做錯了。
控制器代碼-
var app = angular.module('filterSample',[]); app.controller('filterCtrl',函數($ scope){
$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
屬性中搜索,而不是在整個對象中搜索一樣。
將ng-model更改為search.name
<div ng-controller="filterCtrl">
<input type="text" ng-model="search.name" />
<ul border="1px" ng-repeat="msg in data.messages | filter:search:startsWith">
<li>{{msg.name}}</li>
</ul>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.