角度过滤器对象图

时间:2016-04-11 18:49:55

标签: angularjs filter

我有一个输入字段和对象图,用于从datalist

中提供过滤选项
<datalist id="fromStationList">
<select id="fromStationSelectList">  
<option ng-repeat="(LocObject, locValue) in filterCityList()">{{locValue.cityName}}</option>
</select>
</datalist>

<input  list="fromStationList" type="search" ng-model="fromLocation" class="input-text full-width"/>

---剧本---

// it is an json object recieved from ajax call
$scope.locationsMap = "{"PNQ":{"id":"PNQ","cityName":"Pune"},"BLR":{"id":"BLR","cityName":"Bengaluru"},"DEL":{"id":"DEL","cityName":"Delhi"},"AGC":{"id":"AGC","cityName":"Agra"}}"

$scope.filterCityList = function() {
var result = {};
if($scope.fromLocation == undefined)
    return $scope.locationsMap;
var enteredKeywords = ('' + $scope.fromLocation).toLowerCase();

angular.forEach($scope.locationsMap, function(value, key) {
     var cityValue = ('' + value.cityName).toLowerCase();
    if ((cityValue).indexOf(enteredKeywords) > -1) {
        result[key] = value;
    }
});

return result;

}

但是只有当我输入ex的第一个字母时它才会过滤。在输入“p”时它表示Pune,但在输入“g”时它并不表示agra或bengaluru。

0 个答案:

没有答案