gpt4 book ai didi

javascript - 如何使用 Parse.promise javascript 定义 Promise 数组并获取结果数组 [parse.com]

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

我正在尝试从一系列 promise 中获取一系列结果。我能够通过没有得到结果数组来定义 promise 数组下面是我的代码

function get_order_selection(order){
var itemList=[];
var promise = Parse.Promise.as();
var query = new Parse.Query("Order_Selection");
query.equalTo("order", order);
query.include('wine');
promise = query.find().then(function(results) {
console.log("Order_Selection received for order.id: " + order.id + " result(s): " +results.length);
console.log(results);

var i = 0;
var size = results.length;
while(i<size){
var name = results[i].get('wine').get('name');
var unitPrice = results[i].get('unitPrice');
var quantity = results[i].get('quantity');
var smallURL = results[i].get('wine').get('small_picture').url();
console.log("Order_Selection-> name: "+name+ " unitPrice: "+unitPrice+" quantity: "+quantity+" smallURL: "+smallURL);
var item = {
name: name,
unitPrice: unitPrice,
quantity: quantity,
smallURL: smallURL
}
itemList.push(item);
i++;
}
console.log("get_order_selection: itemList:"+itemList);
return itemList;
});
return promise;
}

在我的主要通话中

        var i = 0;
var size = results.length;
while(i<size){

selection_query.push(get_order_selection(results[i]));

i++;
}

我无法获取数组中的结果。

            Parse.Promise.when(selection_query).then(
function(results,results2,results3){
console.log("Promise results");
console.log("Promise results.length:"+results.length);
console.log("Promise results2.length:"+results2.length);
var responseJSON = {orders: orders_list};
response.success(responseJSON);
}
);

最佳答案

我找到了答案。console.log("arguments.length:"+arguments.length);

使用参数。

        Parse.Promise.when(selection_query).then(
function(results,results2,results3){
console.log("arguments.length:"+arguments.length);
console.log("Promise results");
console.log("Promise results.length:"+results.length);
console.log("Promise results2.length:"+results2.length);
var responseJSON = {orders: orders_list};
response.success(responseJSON);
}
);

关于javascript - 如何使用 Parse.promise javascript 定义 Promise 数组并获取结果数组 [parse.com],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27614260/

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