gpt4 book ai didi

javascript - 解析云代码 - promise 问题

转载 作者:行者123 更新时间:2023-12-02 15:20:32 24 4
gpt4 key购买 nike

这是我的代码

Parse.Cloud.define('filters', function(request, response){
var _ = require('underscore');
var customerGeoPoint = request.params.geolocation;
var rating = request.params.rating

var finalList = [];
// var arr = [];
var promises = [];
var query = new Parse.Query('ServiceProvider');
query.withinMiles("geoLocation", customerGeoPoint, 10);

query.find().then(function(spobjs){
return spobjs
}).then(function(newval){
var query2 = new Parse.Query('Customer');
for(i in newval){
query2.withinMiles('geoLocation', newval[i].get('geoLocation'), newval[i].get('serviceRadius'));
var sp = query2.first()
if(sp != null)
{
finalList.push(newval[i]);
}
}
return finalList ;
}).then(function(resval){
var arr = [];
var arr = _.sortBy(resval,'averageRating'); ** This Line doesn't work **
console.log(arr[0]);
return arr ;
}).then(function(checkval){

response.success(checkval);

},function(error){
// console.log(error);
response.error(error);
});

});

在上面的代码中,显示“This Line does not work”的行没有执行任何操作。我需要 underscore.js 但它仍然无法对数组进行排序。 finalList 值返回到 then promise 之后,但它不会对其进行排序并返回与 finalList 相同的值>。有人可以告诉我这段代码有什么问题吗?

最佳答案

当使用underscorejs对解析对象进行排序时,迭代器必须使用get()返回属性的值...

var arr = _.sortBy(resval, function(o) { return o.get('averageRating'); });

关于javascript - 解析云代码 - promise 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34126550/

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