Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
orderBy在AngularJS中如何处理$odd和$偶数?_Angularjs_Twitter Bootstrap - Fatal编程技术网

orderBy在AngularJS中如何处理$odd和$偶数?

orderBy在AngularJS中如何处理$odd和$偶数?,angularjs,twitter-bootstrap,Angularjs,Twitter Bootstrap,我有两列,都包含来自同一数组的项。我想达到砖石的效果,因为每个砖的高度都不一样 <div class="col-md-6"> <div class="tile" ng-repeat="item in items| orderBy: 'id'" ng-if="$odd"> <button ng-click="alert($index)"></button> </div> </div>

我有两列,都包含来自同一数组的项。我想达到砖石的效果,因为每个砖的高度都不一样

 <div class="col-md-6">
     <div class="tile" ng-repeat="item in items| orderBy: 'id'" ng-if="$odd">
         <button ng-click="alert($index)"></button>
     </div>
 </div>

 <div class="col-md-6">
     <div class="tile" ng-repeat="item in items| orderBy: 'id'" ng-if="$even">
         <button ng-click="alert($index)"></button>
     </div>
 </div>

Angular将在已排序的数组上执行奇偶交替还是在数组中存储元素的方式?

Angular将在数组中存储元素的方式上进行交替。如果要组织我将使用的数组,请在分配给Angular$scope之前进行排序。

基于尝试下面的代码,Angular在基于orderBy筛选器排序后似乎确实应用了$odd和$偶数。但是,这只能在单个ng repeat指令中正常工作。我将修改您的代码,使其如下所示:

angular.modulemyApp,[] .controllerItemController,函数$scope{ $scope.items=[{ 身份证号码:50 }, { 身份证号码:1 }, { 身份证号码:2 }, { 身份证号码:5 }, { 身份证号码:3 }]; $scope.alert=functionidx{ console.logidx; }; }; {{item.id} {{item.id} 角度过滤器返回源数组的副本。ng重复应用于副本


您的示例案例可以工作,但它将创建两倍于$watch元素的数量,并且如果行数发生变化,您可能会遇到数据在列之间来回移动的奇数闪烁。另外,因为数组是基于0的,所以您的行将是向后的。

我认为这不准确。Angular 1.4.x似乎在orderBy之后应用了$odd和$偶数属性。