gpt4 book ai didi

javascript - AngularJS 资源结果未定义

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

这可能只是我访问资源对象的方式,但我有以下服务:

angular.module('appointeddPortalApp')
.factory('Salon', function ($resource) {
// Service logic
// ...

// Public API here
return $resource('http://api.appointeddcore.dev/organisation/:id', {id: '@id'}, {
update: { method: 'PUT' },
query: { method: 'GET', isArray: false}
});
});

我正在使用这样的查询方法:

var data = Salon.query($scope.options);
console.log(data);

来自console.log():

Resource {$get: function, $save: function, $query: function, $remove:
function, $delete: function…}
offices: Array[20]
total: 33
__proto__: Resource

我的问题是尝试访问 totaloffices 我未定义

console.log(data.total); // undefined

最佳答案

因为 Salon.query() 立即返回一个空对象,并在数据存在时更新变量数据,请尝试以下操作:

var data = Salon.query(function(callbackdata){
//function is called on success
console.log(callbackdata);
console.log(callbackdata.total);
});

关于javascript - AngularJS 资源结果未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17187774/

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