我想在AngularJS中实现一个搜索框,但实现它的方式对我来说还不清楚。
我有一个过滤数组的函数,但我不知道如何将过滤后的数组与我在数组中实际拥有的数据进行比较,以匹配某些文本。
这是我的JS:
$scope.selectAll = function(modelItemsList) {
console.debug("searchText", $scope.searchText);
filteredArray = filterFilter($rootScope.modelItemsList, $scope.searchText);
console.log(filteredArray);
$rootScope.temp = [];
console.log($scope.modelItemsList);
$rootScope.modelItemsList.allItemsSelected = !$rootScope.modelItemsList.allItemsSelected;
console.log($rootScope.modelItemsList.allItemsSelected);
if ($rootScope.modelItemsList.allItemsSelected) {
for (var i = 0; i < $scope.modelItemsList.length; i++) {
$rootScope.temp.push($scope.modelItemsList[i].name);
console.log($scope.modelItemsList[i].name);
$scope.modelItemsList[i].isChecked = $rootScope.modelItemsList.allItemsSelected;
console.log($scope.modelItemsList[i].isChecked);
console.log($rootScope.modelItemsList.allItemsSelected);
}
} else if (!$rootScope.modelItemsList.allItemsSelected) {
for (var i = 0; i < $scope.modelItemsList.length; i++) {
$scope.modelItemsList[i].isChecked = $rootScope.modelItemsList.allItemsSelected;
$rootScope.temp = [];
console.log($scope.modelItemsList[i].isChecked);
}
}
}
这是我的HTML:
<!-- /.modal-search-box -->
<div class="md-list">
<md-checkbox ng-model="modelItemsList.allItemsSelected" ng-change="selectAll(modelItemsList)">
{{"Alle markieren" | translate}}
</md-checkbox>
<md-list>
<md-list-item class="md-3-line" ng-repeat="modelItem in modelItemsList | filter:searchText track by $index">
<div class="md-list-item-text">
<md-checkbox ng-model="modelItem.isChecked " aria-label="Checkbox 1" ng-change="selectModelItem(modelItem)">
<h3>{{ $eval('modelItem.'+propertyName) }}</h3>
<p>{{ $eval('modelItem.'+propertyDesc) }}</p>
</md-checkbox>
</div>
</md-list-item>
</md-list>
<md-button class="md-primary" ng-click="saveValues()">{{"Aktualisieren" | translate}}</md-button>
</div>
如何将过滤后的数组中的部分文本与我在数组中实际拥有的内容进行比较。提前谢谢!