【发布时间】:2017-06-20 00:33:25
【问题描述】:
我知道这是一个基本问题,但我在任何地方都找不到任何相关的教程或文档。
我尝试使用以下代码生成 trNgGrid 表:
<div><button type="submit" ng-click="requestJSON()">X</button></div>
<div ng-controller="SearchController">
<table tr-ng-grid='' items="data"></table>
</div>
<script type="text/javascript">
app.controller("SearchController", function ($scope, $http) {
$scope.requestJSON = function () {
var httpRequest = $http.get(url, {params: parameters})
.success(function (data, status, headers, config) {
// Call table render function
$scope.data = data;
})
.error(function (data, status, headers, config) {
})
};
});
</script>
$scope.data 返回就好了,但表格根本不会显示。 当我像这样将数据复制并粘贴到 $scope.data 时:
$scope.data = [{"name": "myName", "age": 50}]
表格按原样显示。
请帮忙。
更新:
我在 GitHub 的 trNgGrid 论坛上询问,终于得到了解决方案。
问题是我没有指定表中的列。 当我为每一列添加“tr”时,数据应该出现在表格上。所以表格代码应该是这样的:
<table tr-ng-grid='' items="data">
<tr>
<th field-name="name"></th>
<th field-name="age"></th>
</tr>
</table>
【问题讨论】:
标签: javascript angularjs html-table