AngularJS+;自举&x2B;滤器

AngularJS+;自举&x2B;滤器,angularjs,twitter-bootstrap,filter,Angularjs,Twitter Bootstrap,Filter,我正在尝试筛选用户列表。我正在使用一个自定义的引导版本,希望显示一个4列表 到目前为止,我有以下代码: <div ng-repeat="user in users | filter:searchValue | orderBy: 'username'"> <span ng-switch on="$index % 4"> <span ng-switch-when="0"> <div class="row-flu

我正在尝试筛选用户列表。我正在使用一个自定义的
引导版本,希望显示一个4列表

到目前为止,我有以下代码:

<div ng-repeat="user in users | filter:searchValue | orderBy: 'username'">
    <span ng-switch on="$index % 4">
        <span ng-switch-when="0">
            <div class="row-fluid">
                <div class="span3" ng-if="users[$index+0]">
                    <user-item ng-model="users[$index+0]" on-click="showUser(userId)"></user-item>
                </div>
                <div class="span3" ng-if="users[$index+1]">
                    <user-item ng-model="users[$index+1]" on-click="showUser(userId)"></user-item>
                </div>
                <div class="span3" ng-if="users[$index+2]">
                    <user-item ng-model="users[$index+2]" on-click="showUser(userId)"></user-item>
                </div>
                <div class="span3" ng-if="users[$index+3]">
                    <user-item ng-model="users[$index+3]" on-click="showUser(userId)"></user-item>
                </div>
            </div>
        </span>
    </span>
</div>

到目前为止,在没有过滤器集的情况下,它可以完美地工作。 当我设置一个
searchValue
时,
$index
不能显示正确的值(它总是从0开始到过滤数组的长度)


我的问题是:有没有一种方法可以正确地在
4-cols
表中显示结果并过滤结果?

我认为使用引导css创建4列表不需要添加条件,只需在
col-*
元素中使用
ng repeat
,或者使用自定义
span
类即可(我假设是使用引导的mixin创建行和列)

HTML

<input ng-model="searchValue.username" />
<div class="row-fluid">
  <!-- simply change col-xs-3 to span3 -->
  <div class="col-xs-3" ng-repeat="user in users | filter:searchValue | orderBy: 'username'">
    {{user.username}}
  <user-item ng-model="user" on-click="showUser(user.id)"></user-item>
  </div>
</div>

{{user.username}

如果上面的标记在您的情况下不起作用,因为您使用的是自定义引导,那么您最好使用一个过滤器,该过滤器将当前数组划分为代表行-列关系的子数组部分,回答是

下次尝试拍摄它所基于的ngTasty表o bootstrap css table:)

好吧,我想从整个
用户数组中获取
$index
。我的意思是,如果
过滤器设置为
null
$index
将从0变为100(例如)。当我将过滤器设置为
98
(说用户名类似于
username+$index
)时,我希望得到
$index=97
,但我得到了
0
。检查此选项:搜索的期望值:4
name4
name40
。结果是
name5
name7
name8
name9
@Manitoba,您是否试图保留表的4列结构,同时仅显示与查询匹配的结果?还有在别人身上留着空的牢房?你好,谢谢你的回答。您的上一个解决方案出现错误:
error:[$rootScope:infdig]10$digest()已达到迭代次数。流产。检查控制台上是否有这些杂物。