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

标签 javascript angularjs ngtable

我尝试使用 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/

相关文章:

javascript - 如何重新加载 angularJs ng-table

Javascript动态IF正则表达式条件没有eval?

javascript - Select2 Ajax 无法选择从 API 拉入的选项

javascript - Access-Control-Allow-Origin 不适用于同一域内的 iframe

javascript - 为什么这会导致继承?

css - 使此表列宽度适合。不太宽也不太窄

javascript - 使用 Context 进行 React State 过滤

angularjs - 在导航到其他 View 之前警告用户

angularjs - Angular JS : what are the problems/pitfalls of using Angular?

angularjs - 将过滤器文本字段的字符限制为 10 - ngTable