【问题标题】:add column dynamically to table json and angular.js将列动态添加到表 json 和 angular.js
【发布时间】:2013-08-16 06:14:06
【问题描述】:

我想在表格中动态添加一列。我的代码基于 angularjs 和 json。表结构在文件 abc.json 中定义。我想给这张表加一列。我不想动态地这样做。

我尝试了以下方法:

var newCol = [{name: "abc", type: "textarea", displayName: "ABC"}];
table.push(newCol);
$scope.cfg = table;
table = angular.copy($scope.cfg);

我可以添加新列,但列数据始终未定义。此外,我希望此列在添加后存储在表中。

【问题讨论】:

  • 请详细说明你到目前为止做了什么。显示一些实现细节。
  • @EpokK,我尝试了你的建议。似乎已添加该列,但我无法查看数据。数据始终是“未定义的”。

标签: json angularjs


【解决方案1】:

检查一下:

(在您的控制器中)

--- JAVASCRIPT ---
$scope.table = ['1', '2', '3']; // abc.json
$scope.table.push('4'); // add column

(你的结构)

--- HTML ---
<table>
   <tr ng-repeat="column in table">
      <td>
         <span ng-bind="column"></span>
      </td>
   </tr>
</table>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-06
    • 2021-06-05
    • 2016-08-17
    • 1970-01-01
    • 2013-07-16
    • 2017-04-15
    相关资源
    最近更新 更多