Javascript 需要在Angular JS中使用ng grid逐列呈现数据
我有以下格式的数据Javascript 需要在Angular JS中使用ng grid逐列呈现数据,javascript,json,angularjs,ng-grid,Javascript,Json,Angularjs,Ng Grid,我有以下格式的数据 $scope.myStudentData = {"Moroni":{"id":"1","grade":"A"},"Tiancum":{"id":"2","grade":"B"}} 但网格所期望的是 $scope.myGridOptions = [{"details":"id", "Moroni":"1", "Tiancum":"2"},{"details":"grade", "Moroni":"A", "Tiancum":"B"}]; 这是因为ng网格选项需要行。 有没有
$scope.myStudentData = {"Moroni":{"id":"1","grade":"A"},"Tiancum":{"id":"2","grade":"B"}}
但网格所期望的是
$scope.myGridOptions = [{"details":"id", "Moroni":"1", "Tiancum":"2"},{"details":"grade", "Moroni":"A", "Tiancum":"B"}];
这是因为ng网格选项需要行。
有没有一种方法可以使一个网格列明智?
注意:我希望在一些派生字段之间使用角度双向绑定,因此,不会将数据转换为网格所期望的格式。您实际上可以
$scope.gridOptions = {
data: users,
columnDefs: [
{field: 'id', displayName: 'Member ID'},
{field: 'lastName', displayName: 'Last Name'},
{field: 'firstName', displayName: 'First Name'},
{field: 'email', displayName: 'Email'},
{field: 'phone', displayName: 'Phone'}
};
及
其中,users
是对象数组和列定义,即要显示的列。field属性必须与对象中的字段匹配
可以找到gridoptions的API
<div ui-grid="gridOptions"></div>