【问题标题】:$index orderby in angularjsangularjs中的$index orderby
【发布时间】:2014-06-09 07:40:18
【问题描述】:

我为我的问题创建了 jsfiddle:

http://jsfiddle.net/CeNyg/1/

<div ng-repeat="char in blockCharJson" row="{{char.row}}" column="{{char.column}}" >{{char.id}}</div>


var app = angular.module("myApp", []);
app.controller('Ctrl', function($scope) {
    $scope.blockCharJson = {};
    console.log($scope.blockCharJson);
    for(var i=0; i<16; i++){
        for(var j=0; j<16; j++ ){
            $scope.blockCharJson[i*16+j] = {id:i*16+j, row:i, column:j }
        }
    }
});

现在告诉我应该怎么做才能对 0 到 255 的元素进行排序。 因为默认情况下它在 1 之后需要 10...我不知道该怎么做

【问题讨论】:

    标签: angularjs indexing sql-order-by


    【解决方案1】:

    使用数组代替对象:http://jsfiddle.net/CeNyg/2/

    基本上,对象{} 没有保证项目的顺序,而数组[] 则有。创建数组后:

    $scope.blockCharJson = [];,

    您可以通过push 函数将项目添加到数组的末尾。例如:

    $scope.blockCharJson.push({id:i*16+j, row:i, column:j });

    【讨论】:

      猜你喜欢
      • 2013-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多