一旦我有搜索结果呈现我突出搜索关键字,所以如果多个keyowrds搜索过滤器没有突出显示所有关键字只有最后一个搜索关键字被突出显示,我如何使用下面的过滤器突出显示所有搜索关键字?
filter.js
angular.module('loggingApp').filter('trusted', function($sce) {
return function(text, phrase) {
if (phrase) {
var data = text.replace(/[|&;$%@"<>()+,]/g, "");
data = data.replace(new RegExp('(' + phrase + ')', 'gi'),
'<span class="highlighted">$1</span>');
return $sce.trustAsHtml(data);
}
text = text.replace(/[|&;$%@"<>()+,]/g, "");
return $sce.trustAsHtml(text);
};
});
modalCtrl.js
// e.g var data.searchStr = ["standard","industry"];
angular.forEach(data.searchStr,function(item) {
$scope.searchStr = item;
});;
$scope.showMessages = data.messageObj;
main.html中
<tr ng-repeat="item in showMessages | filter:searchStr" >
<td >{{item.filename}}</td>
<td class="serverResults" ng-bind-html="item.value | trusted:searchStr">{{item.value}}</td>
</tr>