通用元素的Ng重复

时间:2016-06-29 10:29:26

标签: angularjs json ng-repeat

我有问题。我想根据电话在不同的json上进行ng-repeat。

我想这样做:当在elementHeaderATMT上进行调用时 我显示以下代码

window.TreeView.GetItem([0]).Click()

否则这个...... 但如果我想自动这样做我应该做什么

<table class="table">
                    <thead>
                            <tr ng-repeat="element in elementsHeaderATMT">
                                <th>{{ element.transportLine }}</th>
                                <th>{{ element.station }}</th>
                                <th>{{ element.transformer }}</th>
                                <th>{{ element.park }}</th>
                                <th>{{ element.lineMT }}</th>
                                <th>{{ element.section }}</th>
                                <th>{{ element.CD }}</th>
                                <th>{{ element.transformerCdCm }}</th>
                                <th>{{ element.element }}</th>
                                <th>{{ element.type }}</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ng-repeat="element in elementsDataATMT">
                                <td>{{ element.transportLine }}</td>
                                <td>{{ element.station }}</td>
                                <td>{{ element.transformer }}</td>
                                <td>{{ element.park }}</td>
                                <td>{{ element.lineMT }}</td>
                                <td>{{ element.section }}</td>
                                <td>{{ element.CD }}</td>
                                <td>{{ element.transformerCdCm }}</td>
                                <td>{{ element.element }}</td>
                                <td>{{ element.type }}</td>
                            </tr>
                        </tbody>
                    </table>

我的Json就是这个

<table class="table">
                    <thead>
                            <tr ng-repeat="element in elementsHeaderBT">
                                <th>{{ element.CD }}</th>
                                <th>{{ element.Cuadro }}</th>
                                <th>{{ element.Salida }}</th>
                                <th>{{ element.type }}</th>
                                <th>{{ element.element }}</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ng-repeat="element in elementsDataATMT">
                                <td>{{ element.CD }}</td>
                                <td>{{ element.Cuadro }}</td>
                                <td>{{ element.Salida }}</td>
                                <td>{{ element.type }}</td>
                                <td>{{ element.element }}</td>
                            </tr>
                        </tbody>
                    </table>

}

我的控制器就是这个

{
"ATMT": {

    "header": [{

        "transportLine": "Linea Transporte",
        "station": "Estracion",
        "transformer": "Trafo",
        "park": "Parque",
        "lineMT": "Linea MT",
        "section": "Tramo",
        "CD": "CD",
        "transformerCdCm": "Trafo CD/CM",
        "element": "Elemento",
        "type": "Tipo"

    }],

    "data": [{

        "transportLine": "",
        "station": "ABRERA",
        "transformer": "",
        "park": "25",
        "lineMT": "AGUAS1",
        "section": "",
        "CD": "LL...",
        "transformerCdCm": "",
        "element": "T-1",
        "type": "DIS_MAN_CD"

    }]
},

"BT": {

    "header": [{

        "CD": "CD",
        "picture": "Cuadro",
        "departure": "Salida",
        "type": "Tipo",
        "element": "Elemento BT"


    }],

    "data": [{

        "CD": "C100446",
        "picture": "11",
        "departure": "01",
        "type": "",
        "element": ""

    }]
}
抱歉我的英语不好,但我希望我很清楚 感谢

2 个答案:

答案 0 :(得分:1)

如果我理解你的想法,你喜欢迭代关键,在json中重视元组。 这适合:

<tr ng-repeat="(key, value) in elementsDataATMT ">
  <td> {{key}} </td> <td> {{ value }} </td>
</tr>

答案 1 :(得分:0)

您可以在两个表上使用ng-if,并在控制器中设置变量:

<table class="table" ng-if="elementHeaderATMTCalled">
<table class="table" ng-if="!elementHeaderATMTCalled">

在控制器中,每次拨打电话时,都会更新该变量。

$scope.elementHeaderATMTCalled = true; // or false