gpt4 book ai didi

javascript - 在函数内部返回数据,但不在 html 上查看

转载 作者:行者123 更新时间:2023-11-28 07:44:29 25 4
gpt4 key购买 nike

var app = angular.module('app', ['ui.router','ngTasty']);
app.config(['$urlRouterProvider', '$stateProvider', '$locationProvider', function($urlRouterProvider, $stateProvider, $locationProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('home', {
url: '/',
templateUrl: 'templates/home.html',
controller: function($scope, $http, $location) {
$scope.getData = function(params) {
var dataUrl = 'main/home/?';
$scope.urlApiTwo = dataUrl + params;
return mydata($scope.urlApiTwo, $http);
};
}
});
}]);

function mydata(urxx, $http) {
return $http.get(urxx).then(function(response) {
return {
'rows': response.data.rows,
'header': response.data.header,
'pagination': response.data.pagination,
'abc': response.data.abc
};
});
}

我需要访问 home.html 中的“abc”数据。但这不是 View 。

控制台日志数据:

{"header":[{"name":"Id"},{"name":"Subject"},{"name":"Status"}],"rows":[{"ids":"1","subject":"Hindi","status":"1"},{"ids":"2","subject":"English","status":"1"},{"ids":"3","subject":"Mathematics","status":"1"},{"ids":"4","subject":"Science","status":"1"},{"ids":"5","subject":"Social Science","status":"1"}],"pagination":{"count":"5","page":1,"pages":16,"size":80},"abc":[{"value":"home"}]}

最佳答案

当您使用 $scope.getData 检索数据时,使用返回的 Promise then 方法

$scope.getData(params).then(function(data) {
$scope.abc = data.abs;
});

关于javascript - 在函数内部返回数据,但不在 html 上查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27602086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com