AngularJs NG重复二维数组中的表,每个子阵列一列阵列、个子、组中、AngularJs

2023-09-08 09:26:40 作者:亞洲丨冭孓爺

我有一个数组,我需要把该数组中的表。

$ scope.testArr = [     {'第一':[             {'价值':'1_1','罗尔':'one1},             {'价值':'2_1','罗尔':'two1},             {'价值':'3_1','罗尔':'three1'}         ]     },     {'第二': [             {'价值':'1_2','罗尔':'one2},             {'价值':'2-2','罗尔':'two2},             {'价值':'3_2','罗尔':'three2'}         ]     } ];

所得表应具有4列,每个子阵列应该是一个(或两个)柱(多个)。像这样的:

 one1 | 1_1 | one2 | 1-2
two1 | 2_1 | two2 | 2_2
three1 | 3_1 | three2 | 3_2 

到目前为止,我得到了这一点。它唯一的第一子阵:

<表>     < TBODY NG重复=测试testArr>         < TR NG重复=T1在test.first>             < TD> {{t1.rolle}}< / TD>             < TD> {{t1.value}}< / TD>         < / TR>     < / TBODY>    < /表>

我如何添加第二子阵列作为列?这是没有必要必须是一个表。

解决方案

VAR应用= angular.module('应用',[]); app.controller('mainCtrl',函数($范围){     $ scope.testArr = [{         '第一': [{             价值:1_1,             罗尔:one1         },{             价值:2_1,             罗尔:two1         },{             价值:3_1,             罗尔:three1         }]     },{         '第二': [{             价值:1_2,             罗尔:one2         },{             价值:2-2,             罗尔:two2         },{             价值:3_2,             罗尔:three2         }]     }]; });

TD {   边界:1px的固体灰色 } AngularJS快速入门

&LT;脚本SRC =htt​​ps://ajax.googleapis.com/ajax /libs/angularjs/1.2.23/angular.min.js"></script> &LT; D​​IV NG-应用程序=应用程序&GT;     &LT; D​​IV NG控制器=mainCtrl&GT; &LT;表&gt;     &LT; TBODY NG重复=测试testArr&GT;         &LT; TR NG重复=T1在test.first&GT;             &其中; TD&GT; {{t1.rolle}}&所述; / TD&GT;             &其中; TD&GT; {{t1.value}}&所述; / TD&GT;             &LT; TD&GT; {{testArr [1]。第二[$指数] .rolle}}&LT; / TD&GT;             &LT; TD&GT; {{testArr [1]。第二[$指数] .value的}}&LT; / TD&GT;         &LT; / TR&GT;     &LT; / TBODY&GT; &LT; /表&gt;     &LT; / DIV&GT;     &LT; / DIV&GT;

I have an array and I need to put that array in table.

$scope.testArr=[ {'first':[ { 'value':'1_1', 'rolle':'one1' }, { 'value':'2_1', 'rolle':'two1' }, { 'value':'3_1', 'rolle':'three1'} ] }, {'second': [ { 'value':'1_2', 'rolle':'one2' }, { 'value':'2_2', 'rolle':'two2' }, { 'value':'3_2', 'rolle':'three2' } ] } ];

Resulting table should have 4 columns, each subarray should be one(or two) column(s). Like this:

one1 | 1_1 | one2 | 1-2
two1 | 2_1 | two2 | 2_2   
three1|3_1 | three2|3_2

So far I got this. Its only the first subarray:

<table> <tbody ng-repeat="test in testArr"> <tr ng-repeat="t1 in test.first"> <td> {{t1.rolle}} </td> <td> {{t1.value}} </td> </tr> </tbody> </table>

How can I add the second subarray as column? It's not necessary need to be a table.

解决方案

var app = angular.module('app', []);

app.controller('mainCtrl', function ($scope) {


    $scope.testArr = [{
        'first': [{
            'value': '1_1',
            'rolle': 'one1'
        }, {
            'value': '2_1',
            'rolle': 'two1'
        }, {
            'value': '3_1',
            'rolle': 'three1'
        }]
    }, {
        'second': [{
            'value': '1_2',
            'rolle': 'one2'
        }, {
            'value': '2_2',
            'rolle': 'two2'
        }, {
            'value': '3_2',
            'rolle': 'three2'
        }]
    }];

});

td {
  border:solid 1px grey
}

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="app">
    <div ng-controller="mainCtrl">
<table>
    <tbody ng-repeat="test in testArr">
        <tr ng-repeat="t1 in test.first">
            <td>{{t1.rolle}}</td>
            <td>{{t1.value}}</td>
            <td>{{testArr[1].second[$index].rolle}}</td>
            <td>{{testArr[1].second[$index].value}}</td>
        </tr>
    </tbody>
</table>
    </div>
    </div>