gpt4 book ai didi

javascript - $resource 无法从 json 获取数组

转载 作者:行者123 更新时间:2023-12-03 10:42:15 25 4
gpt4 key购买 nike

我想从服务器(java)获取数组对象。下面是 Angular 方法:

service.getAthors = function(){
var deferred = $q.defer();

var authors = authorResource.query(function() {
console.log(authors);
}).$promise.then( function(){
deferred.resolve( "Adding book have gone correctly." );
}, function(){
deferred.reject("Error during adding new book.");
});
}

在控制台 Firebug 中我看到这个:[{"author_id":7,"author":"Dan Brown"}] 但authors数组是空的。你能告诉我为什么吗?

最佳答案

您需要将作者分配给返回的服务器数据。

authorResource.query(function() {
console.log(authors);
}).$promise.then( function(data){
authors = data;
deferred.resolve( "Adding book have gone correctly." );
}, function(){
deferred.reject("Error during adding new book.");
});

关于javascript - $resource 无法从 json 获取数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28721580/

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