角JS:HTML表中的列排序不工作工作、JS、HTML

由网友(曾经再美也是伤)分享简介:我创建了一个角JS的申请表中排序值。在表中的某些列是动态的,基于JSON子阵列上创建I've created an application in angular-JS for sorting values in tables. Certain columns in tables are dynamic and bee...

我创建了一个角JS的申请表中排序值。在表中的某些列是动态的,基于JSON子阵列上创建

I've created an application in angular-JS for sorting values in tables. Certain columns in tables are dynamic and been created based on the child JSON array

例如JSON的结构从服务返回的是那里的主要JSON的其他领域包含另一个JSON数组这是其他列的结构,

For example the JSON structure returning from a service is in the structure where the others field of the main JSON contains another JSON array which is the additional columns,

在下面的结构的结果,第一个对象有文件4 ,结果第二个对象有文件1 和文件2 ,结果第三个对象有文件2 和文件3 并结果第四对象有文件3 和文件4

In the below structure the first object has File 4, second object has File 1 and File 2, third object has File 2 and File 3 and fourth object has File 3 and File 4

所以一起将有另外四个动态列即文件1,文件2,文件3,文件4 每个对象都有相应的文件字段值,有时present有时不是present。

so all together there will be four additional dynamic columns i.e File 1, File 2, File 3, File 4 each object has value for the corresponding File field, sometime present sometime not present.

<th ng-repeat="colms in getcolumns()"><a ng-click="sort_by("dont know wat to pass")">
              <i>{{colms}}</i>
            </a>
</th>

我已经展示与动态列也很好,我实现了使用角JS每列排序表。但问题在于,排序工作所有表列以外的动态列

I've shown the tables with the dynamic columns perfectly also I've implemented the sorting for each columns using angular-js. But the problem is that the sorting is working for all table columns except the dynamic columns

谁能告诉我,这一些解决方案

Can anyone please tell me some solution for this

我的JS-小提琴如下

演示

Demo

推荐答案

我明白你不能改变,为您带来的DATAS服务,但你拥有了它你的控制器内后,就可以把它改造。我为您建立一个函数,应该改变你的列表的另一列到具有id作为key和value值作为单独的列。

I understand you cant change the service that brings you the datas but you can transform it after you have it inside your controller. I created a function for you that should change your list's other column into individual columns having id as key and value as value.

$scope.transformDatas = function() {
    $scope.newDatas = [];
    for(var i in $scope.datas) {
        var auxData = {};
        angular.forEach($scope.datas[i], function(value, key) {
            if(key != 'others')
                auxData[key] = value;
            else {
                for(var j in $scope.datas[i].others) {
                    var nth = 1;
                    while(auxData[$scope.datas[i].others[j].id + ',' + nth] != undefined)
                        nth++;
                    auxData[$scope.datas[i].others[j].id + ',' + nth] = $scope.datas[i].others[j].value;
                }
            }
        });
        $scope.newDatas.push(auxData);
    }
}

从这里到你的目标很简单的工作,你已经做了它(排序正常的字段)。

From here to your goal it's easy job, you already done it (sorting the normal fields).

http://jsfiddle.net/KR6Xh/15/

阅读全文

相关推荐

最新文章