如何从数组中提取特定数据以显示在 ui-grid 上
How to extract specific data from array to display on ui-grid
我正在尝试更正以下 ui- 网格:
为了仅显示我想要的对象 alquiler 和对象 usuario 的信息,这两个对象都包含在 Rent (UsuarioHasAlquiler) 对象中。
我尝试了以下方法:
'use strict';
angular.module('myApp.view1', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/view1', {
templateUrl: 'resources/view1/view1.html',
controller: 'View1Ctrl'
});
}])
.controller('View1Ctrl', ['$scope','$http',function($scope,$http) {
$scope.rents = [];
$scope.requestObject = {"pageNumber": 0,"pageSize": 0,"direction": "","sortBy": [""],"searchColumn": "string","searchTerm": "","userRent": {}};
$http.post('rest/protected/userRent/getAll',$scope.requestObject).success(function(response) {
console.log("response",response)
$scope.rents = response.usuarRent;
console.log("$scope.items",$scope.rents[1])
// console.log("Tipo de usuario:", $scope.usuarios.tipos)
});
$scope.gridOptions = { data: rents,
columnDefs: [{ field: 'idUsuarioHasAlquiler', displayName: 'ID'},
{ field: 'usuario.firstname', displayName: 'First Name'},
{ field: 'alquiler.name', displayName: 'Item Name'},
{ field: 'estado_renta', displayName: 'Returned'}]
};
}]);
虽然请求成功,但我无法从对象中提取我想要显示在网格上的内容。
<div class="container">
<div class="container">
<h3 class="text-center">Rents</h3>
<hr>
</div>
<div class="container">
<div class="row">
<div ui-grid="gridOptions" class="myGrid"></div>
<br>
<button type="button" ng-click="" class="btn btn-primary">Add</button>
<button type="button" ng-click="" class="btn btn-success">Edit</button>
<button type="button" ng-click="" class="btn btn-danger">Delete</button>
</div>
</div>
</div>
我希望有人能指出我正确的方向。感谢并为西班牙语感到抱歉。
我创建了一个 plunker based on your data,它工作正常。据我所知,你的版本和工作版本之间的唯一区别是你将 $scope.gridOptions.data
设置为 rents
,而不是 $scope.rents
.
我可以重现您的问题的唯一方法是在您的 html 中设置 ui-grid="{data:rents}"
,这不会将您的列定义应用于网格。您是否偶然从 ui-grid
属性中复制 data:rents
并将其粘贴到您的 $scope.gridOptions
对象中?在这种情况下,应该不会显示任何内容,因为 rents
未定义。
我正在尝试更正以下 ui- 网格:
为了仅显示我想要的对象 alquiler 和对象 usuario 的信息,这两个对象都包含在 Rent (UsuarioHasAlquiler) 对象中。
我尝试了以下方法:
'use strict';
angular.module('myApp.view1', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/view1', {
templateUrl: 'resources/view1/view1.html',
controller: 'View1Ctrl'
});
}])
.controller('View1Ctrl', ['$scope','$http',function($scope,$http) {
$scope.rents = [];
$scope.requestObject = {"pageNumber": 0,"pageSize": 0,"direction": "","sortBy": [""],"searchColumn": "string","searchTerm": "","userRent": {}};
$http.post('rest/protected/userRent/getAll',$scope.requestObject).success(function(response) {
console.log("response",response)
$scope.rents = response.usuarRent;
console.log("$scope.items",$scope.rents[1])
// console.log("Tipo de usuario:", $scope.usuarios.tipos)
});
$scope.gridOptions = { data: rents,
columnDefs: [{ field: 'idUsuarioHasAlquiler', displayName: 'ID'},
{ field: 'usuario.firstname', displayName: 'First Name'},
{ field: 'alquiler.name', displayName: 'Item Name'},
{ field: 'estado_renta', displayName: 'Returned'}]
};
}]);
虽然请求成功,但我无法从对象中提取我想要显示在网格上的内容。
<div class="container">
<div class="container">
<h3 class="text-center">Rents</h3>
<hr>
</div>
<div class="container">
<div class="row">
<div ui-grid="gridOptions" class="myGrid"></div>
<br>
<button type="button" ng-click="" class="btn btn-primary">Add</button>
<button type="button" ng-click="" class="btn btn-success">Edit</button>
<button type="button" ng-click="" class="btn btn-danger">Delete</button>
</div>
</div>
</div>
我希望有人能指出我正确的方向。感谢并为西班牙语感到抱歉。
我创建了一个 plunker based on your data,它工作正常。据我所知,你的版本和工作版本之间的唯一区别是你将 $scope.gridOptions.data
设置为 rents
,而不是 $scope.rents
.
我可以重现您的问题的唯一方法是在您的 html 中设置 ui-grid="{data:rents}"
,这不会将您的列定义应用于网格。您是否偶然从 ui-grid
属性中复制 data:rents
并将其粘贴到您的 $scope.gridOptions
对象中?在这种情况下,应该不会显示任何内容,因为 rents
未定义。