gpt4 book ai didi

javascript - AngularJS:在列和行上带有 ng-repeat 的表

转载 作者:行者123 更新时间:2023-12-03 04:16:34 24 4
gpt4 key购买 nike

我正在尝试使用具有双入口点的 angularJS ng-repeat 构建一个表。这是一个例子:

         Column A   Column B    Column C
Object 1 X Y
Object 2 P
Object 3 N

在上表中,“对象 1”有 2 个子对象:X 和 Y,分别属于 A 列和 C 列。

我需要能够将行内容与列标题匹配。我不确定我需要什么 JSON 结构或如何正确使用 ng-repeat 来做到这一点?

最佳答案

我会考虑第三方库,例如 ngTable处理这样的逻辑。开源社区普遍已经为此类问题想到了很好的解决方案。

你的例子:

controller.js

angular.module('yourmodule', ["ngTable"])
.controller('exampleController', ($scope, $service, NgTableParams) => {

// Get a JSON object from your backend of choice
$service.getObjects().then(rows => {
$scope.table_data = new NgTableParams({}, {dataset: rows})
})
})

template.html

<div ng-controller="exampleController">
<table ng-table="table_data">
<tr ng-repeat="row in $data">
<td title="ColA"></td>
<td title="ColB"></td>
<td title="ColC"></td>
</tr>
</table>
</div>

关于javascript - AngularJS:在列和行上带有 ng-repeat 的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44114997/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com