gpt4 book ai didi

javascript - AngularJS - Ng-Table 不会解析标题

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:44:04 26 4
gpt4 key购买 nike

我尝试使用 Ng-table 创建一个表格 View ,它可以通过 AngularJS 参数进行控制。

要控制标题文本,我需要将其放在 data-title 或 ng-data-title 中(例如:data-title="'Test'")

但是,它总是使表头为空。 enter image description here

而不是填充它: enter image description here

代码片段:

<td ng-repeat="v in tableSettings.data" data-title="v.name">
{{v.data?v.data(row):row[v.id]}}
</td>

完整代码:

<table ng-table="table" class="table" show-filter="{{tableSettings.filter}}">
<tr ng-repeat="row in $data">
<td ng-repeat="v in tableSettings.data" ng-click="tableSettings.click(row)" ng-attr-data-title="'{{v.name}}'"
ng-if="v.type!='switch'"
sortable="'{{sortable?sortable:v.id}}'">
{{v.data?v.data(row):row[v.id]}}
</td>
</tr>
</table

当我尝试将 Angular 解析到其中时,我只得到错误:(按查看错误)

"'{{v.name}}'" "{{v.name}}"

有没有办法修复它,甚至可以从 AngularJS 手动解析它?

最佳答案

好的,问题是 data-title 属性是要与静态文本(众所周知的列)一起使用的,例如 data-title="'My first column'"如果您需要的是动态列,则必须使用 ng-table-dynamic 指令。

例如:

<table ng-table-dynamic="tableParams with cols" show-filter="true" class="table table-bordered table-striped">
<tr ng-repeat="row in $data track by row.id">
<td ng-repeat="col in $columns">{{::row[col.field]}}</td>
</tr>
</table>

注意在指令声明中使用了特殊语法tablePrams with cols。这里的 cols 是一个 $scope 变量,它必须遵循以下模式才能正常工作。

$scope.cols =  [
{ title: 'ID', field: 'id', filter: { id : 'text' }, show: true, sortable: 'id' },
{ title: 'Installation', field: 'installationAt' },
...
];

标题和字段是必需的,而filtershowsortable取决于您的使用场景。

你可以玩这个 code pen

关于javascript - AngularJS - Ng-Table 不会解析标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33922527/

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