[英]How to display array data in AngularJS using ngGrid?
I want to display the following array in an ngGrid 我想在ngGrid中显示以下数组
$scope.pathinfo = ["28.86 GB left on dir1","28.86 GB left on dir2"]
My controller looks like this: 我的控制器如下所示:
$scope.restorePathGridOptions = { data: '$scope.pathInfo',
columnDefs: [
{field: 'entry', displayName: 'Free Space for paths'}
]
}
And this is my HTML: 这是我的HTML:
<div id="RestorepathsGrid" class="gridStyle" ng-grid="restorePathGridOptions">
I am assuming 'entry' is data value of array at indices 0 and 1. 我假设“ entry”是索引0和1处数组的数据值。
But the grid does not show up at all. 但是网格根本不显示。
Any ideas why? 有什么想法吗?
data: '$scope.pathInfo' 数据:“ $ scope.pathInfo”
$scope is not needed here. 这里不需要$ scope。
Also, if you want field entry as in your example, then you have to use array of objects 另外,如果您要像示例中那样输入字段,则必须使用对象数组
Use an array of objects instead of an array: 使用对象数组而不是数组:
$scope.pathinfo = [{entry: "28.86 GB left on dir1"}, {entry: "28.86 GB left on dir2"}]
Notice that the field name of the objects in $scope.pathinfo
should match field name in columnDefs
. 请注意,
$scope.pathinfo
对象的字段名称应与columnDefs
中的字段名称匹配。 This should solve your problem. 这应该可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.