根据不同的数组过滤 searchText
Filter searchText based on different array
我想知道如何使用 Angular 的 searchText 过滤器搜索指定的数组。目前,我正在使用基于输入的 ng-repeat 和 filter:searchText。
问题是 ng-repeat 使用了整个数组的一部分。所以它循环遍历 100 条记录中的 10 条记录。我需要它搜索整个数组而不是它使用的数据集。
<input ng-model="searchText" id="ldrSearch" class="form-control" placeholder="Search" name="Search" type="text">
<tr id="row%% $index %%" ng-click="toggleDetails($event,true)" ng-repeat-start="user in users | filter:searchText" class="leaderboardrow"> ... </tr>
我在@zeroflagL 的建议下解决了这个问题
If you filter the slice then you may currently have less than 10
entries, but you want to filter the whole data set and always have 10
entries displayed? With the entries and pages changing dynamically? In
that case I would use the whole array instead of a slice and add a
second (custom) filter to display only the current slice.
以及this SO post.
唯一的区别是我的 "slice" 我使用变量来设置开始和结束。
<tr id="row%% $index %%" ng-click="toggleDetails($event,true)" ng-repeat-start="user in users | filter:searchText | page:start:end"> .. </td>
app.filter('page',function()
{
return function(arr,start,end)
{
return (arr || []).slice(start, end);
};
});
我想知道如何使用 Angular 的 searchText 过滤器搜索指定的数组。目前,我正在使用基于输入的 ng-repeat 和 filter:searchText。
问题是 ng-repeat 使用了整个数组的一部分。所以它循环遍历 100 条记录中的 10 条记录。我需要它搜索整个数组而不是它使用的数据集。
<input ng-model="searchText" id="ldrSearch" class="form-control" placeholder="Search" name="Search" type="text">
<tr id="row%% $index %%" ng-click="toggleDetails($event,true)" ng-repeat-start="user in users | filter:searchText" class="leaderboardrow"> ... </tr>
我在@zeroflagL 的建议下解决了这个问题
If you filter the slice then you may currently have less than 10 entries, but you want to filter the whole data set and always have 10 entries displayed? With the entries and pages changing dynamically? In that case I would use the whole array instead of a slice and add a second (custom) filter to display only the current slice.
以及this SO post.
唯一的区别是我的 "slice" 我使用变量来设置开始和结束。
<tr id="row%% $index %%" ng-click="toggleDetails($event,true)" ng-repeat-start="user in users | filter:searchText | page:start:end"> .. </td>
app.filter('page',function()
{
return function(arr,start,end)
{
return (arr || []).slice(start, end);
};
});