在这个小提琴中,表格可以被过滤:
http://jsfiddle.net/eBcaB/232/
我添加了截断函数,它会截断文本:
$scope.truncate = function(item){
return item.substring(0,2);
}
但我不确定如何将此函数集成到截断项目而不影响结果的过滤。如何截断文本并保持过滤功能,因此截断过程中删除的任何文本仍然可以过滤?
小提琴src:
<div ng-app>
<div ng-controller="ShoppingCartCtrl">
<br />
<div><strong>Filter Results</strong></div>
<table>
<tr>
<td>By Any: </td>
<td><input type="text" ng-model="search.$" /></td>
</tr>
</table>
<br />
<table border="1">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in items | orderBy:mySortFunction | filter:search">
<td>{{item.Name}}</td>
<td>{{item.Price | currency}}</td>
<td>{{item.Quantity}}</td>
</tr>
</tbody>
</table>
<br />
</div>
</div>
.bold { font-weight:bold; }
table td{
padding: 10px;
}
table th{
font-weight: bold;
text-align: center;
}
function ShoppingCartCtrl($scope) {
$scope.items = [
{Name: "Soap", Price: "25", Quantity: "10"},
{Name: "Shaving cream", Price: "50", Quantity: "15"},
{Name: "Shampoo", Price: "100", Quantity: "5"}
];
$scope.truncate = function(item){
return item.substring(0,2);
}
}