1
我想突出显示正在创建表格的ng-repeat下的搜索文本。 我找到了一个过滤器作为我的解决方案,但它不适用于表格。在表格数据中使用AngularJS过滤器+ ng-repeat突出显示网格中的文本
任何人都可以指出我错在哪里使其工作。
<body ng-app="Demo">
<h1>Hello Plunker!</h1>
<div class="container" ng-controller="Demo">
<input type="text" placeholder="Search" ng-model="search">
<table>
<thead>
<th>Some</th>
<th>MyName</th>
</thead>
<tbody>
<tr ng-repeat="item in data | filter:search"
>
<td>
<td>{{item.title}}</td>
<td>{{item.name}}</td>
</td>
</tr>
</tbody>
<!-- with filter -->
</table>
</div>
<script>
angular.module('Demo', [])
.controller('Demo', function($scope) {
$scope.data = [
{ title: "Bad",name:'kaushik' },
{ title: "Good",name:'1kaushik' },
{ title: "Great",name:'2kaushik' },
{ title: "Cool" ,name:'3kaushik'},
{ title: "Excellent",name:'4kaushik' },
{ title: "Awesome",name:'5kaushik' },
{ title: "Horrible",name:'6kaushik' },
]
})
.filter('highlight', function($sce) {
return function(text, phrase) {
if (phrase) text = text.replace(new RegExp('('+phrase+')', 'gi'),
'<span class="highlighted">$1</span>')
return $sce.trustAsHtml(text)
}
})
</script>
</body>
This is working copy of the & demo the same thing I wants is with table.
没有运气与此 –
我只是增加了一个工作片段。具体来说,你是不是可以在你的代码中工作? – Lex
thx mate,相同的代码不适用于闯入者 –