在进行休息调用后在 ui-grid 中显示数据
Display data in ui-grid after making a rest call
我正在尝试显示我在 ui-网格 table 中使用 rest 调用检索到的数据。当我将数据绑定到范围变量并尝试在 html 页面上调用它时,它给出了 TYPEERROR:typeerror cannot read 属性 "data" of undefined angularjs。
我猜它无法获取数据,因此无法获取错误。谁能帮我ui了解我在下面的代码中遗漏了什么:
.controller("widgetCtrl", ["logger", "$scope", "$http", "widgetService", "localizationService",
"gettextCatalog",
function (logger, $scope, $http, widgetService, localizationService, gettextCatalog) {
var myuid;
var myrole;
var locale = localizationService.getLocale();
gettextCatalog.loadRemote("/dashboardplugins/B27F0520-86CF-1033-B9C8-005056A891F8/resources-locale_" +
locale + ".json");
logger.info("WidgetContoller started");
$scope.gridOptions = {};
/**
* load function
*
*/
$scope.load = function () {
widgetService.getData().then(function (response) {
$scope.mydata = response;
$scope.myrole = response.roles[0].split("/").pop();
$scope.myuid = $scope.myuid = response.meta["@href"].split("/").pop();
$scope.gridOptions = {
excludeProperties: "__metadata",
data: [
{
id: $scope.myuid,
name: response.name,
role: $scope.myrole,
state: response.state
}
],
columnDefs: [
{name: "ID", field: "id"},
{name: "Name", field: "name"},
{name: "role", field: "role"},
{name: "state", field: "state"}
],
i18n: [
]
};
});
};
$scope.load();
HtML 页面:
<div ng-Controller="widgetCtrl">
<h1>User Info</h1>
<div ui-grid="gridOptions"></div>
</div>
JSON 数据对象:
Object {data: Object, status: 200, config: Object, statusText: "OK"}
config: Object
data: Object
auth-source: "DATABASE"
createdate: "2016-02-10T20:47:48.408Z"
creator: Object
meta: Object
moddate: "2016-02-10T20:47:48.408Z"
modifier: Object
name: "admin"
perms: Object
roles: Array[1]
state: "ACTIVE"
sys: false
tenant-id: 1
tenant-name: "default"
__proto__: Object
headers: (name)
status: 200
statusText: "OK"
__proto__: Object
看起来您在 getData
函数之外没有对 $scope.gridOptions
的引用,因此请尝试在 getData()
调用上方的某处设置 $scope.gridOptions = {};
。我认为你的错误中的 undefined 指的是 $scope.gridOptions
,假设你上面发布的是你的 logger
函数的结果,它验证你正在取回数据来自您的服务电话。
我正在尝试显示我在 ui-网格 table 中使用 rest 调用检索到的数据。当我将数据绑定到范围变量并尝试在 html 页面上调用它时,它给出了 TYPEERROR:typeerror cannot read 属性 "data" of undefined angularjs。 我猜它无法获取数据,因此无法获取错误。谁能帮我ui了解我在下面的代码中遗漏了什么:
.controller("widgetCtrl", ["logger", "$scope", "$http", "widgetService", "localizationService",
"gettextCatalog",
function (logger, $scope, $http, widgetService, localizationService, gettextCatalog) {
var myuid;
var myrole;
var locale = localizationService.getLocale();
gettextCatalog.loadRemote("/dashboardplugins/B27F0520-86CF-1033-B9C8-005056A891F8/resources-locale_" +
locale + ".json");
logger.info("WidgetContoller started");
$scope.gridOptions = {};
/**
* load function
*
*/
$scope.load = function () {
widgetService.getData().then(function (response) {
$scope.mydata = response;
$scope.myrole = response.roles[0].split("/").pop();
$scope.myuid = $scope.myuid = response.meta["@href"].split("/").pop();
$scope.gridOptions = {
excludeProperties: "__metadata",
data: [
{
id: $scope.myuid,
name: response.name,
role: $scope.myrole,
state: response.state
}
],
columnDefs: [
{name: "ID", field: "id"},
{name: "Name", field: "name"},
{name: "role", field: "role"},
{name: "state", field: "state"}
],
i18n: [
]
};
});
};
$scope.load();
HtML 页面:
<div ng-Controller="widgetCtrl">
<h1>User Info</h1>
<div ui-grid="gridOptions"></div>
</div>
JSON 数据对象:
Object {data: Object, status: 200, config: Object, statusText: "OK"}
config: Object
data: Object
auth-source: "DATABASE"
createdate: "2016-02-10T20:47:48.408Z"
creator: Object
meta: Object
moddate: "2016-02-10T20:47:48.408Z"
modifier: Object
name: "admin"
perms: Object
roles: Array[1]
state: "ACTIVE"
sys: false
tenant-id: 1
tenant-name: "default"
__proto__: Object
headers: (name)
status: 200
statusText: "OK"
__proto__: Object
看起来您在 getData
函数之外没有对 $scope.gridOptions
的引用,因此请尝试在 getData()
调用上方的某处设置 $scope.gridOptions = {};
。我认为你的错误中的 undefined 指的是 $scope.gridOptions
,假设你上面发布的是你的 logger
函数的结果,它验证你正在取回数据来自您的服务电话。