AngularJs ng-repeat 二维数组在表中,每个子数组一列 [英] AngularJs ng-repeat 2D array in table, each subarray one column

查看:22
本文介绍了AngularJs ng-repeat 二维数组在表中,每个子数组一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组,我需要将该数组放入表中.

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

结果表应该有 4 列,每个子数组应该是一(或两)列.像这样:

one1 |1_1 |one2 |1-2二1 |2_1 |两个2 |2_2三1|3_1 |三2|3_2

到目前为止我得到了这个.它只是第一个子数组:

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

如何将第二个子数组添加为列?不一定非得是一张桌子.

解决方案

var app = angular.module('app', []);app.controller('mainCtrl', function ($scope) {$scope.testArr = [{'第一的': [{'值':'1_1','rolle': 'one1'}, {'值':'2_1','rolle': 'two1'}, {'值':'3_1','rolle': 'three1'}]}, {'第二': [{'值':'1_2','rolle': 'one2'}, {'值':'2_2','rolle': 'two2'}, {'值':'3_2','rolle': 'three2'}]}];});

td {边框:实心 1px 灰色}

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><div ng-app="app"><div ng-controller="mainCtrl"><表格><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>

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>

这篇关于AngularJs ng-repeat 二维数组在表中,每个子数组一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
C#最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆