我正在尝试将我的代码部署到Parse,并且我一直收到错误声明:
Update failed with Could not load triggers. The error was Uncaught SyntaxError: Unexpected token } in main.js:454
在下面的代码中,它引用的第454行就是这一行:
}, function(err) {
完整代码:
Parse.Cloud.define("MatchCenterTest", function(request, response) {
//defines which parse class to iterate through
var matchCenterItem = Parse.Object.extend("matchCenterItem");
var query = new Parse.Query(matchCenterItem);
var promises = [];
//setting the limit of items at 10 for now
query.limit(10);
query.find().then(function(results) {
for (i=0; i<results.length; i++) {
url = 'http://svcs.ebay.com/services/search/FindingService/v1';
//push function containing criteria for every matchCenterItem into promises array
promises.push(function() {
return Parse.Cloud.httpRequest({
url: url,
params: {
'OPERATION-NAME' : 'findItemsByKeywords',
'SERVICE-VERSION' : '1.12.0',
'SECURITY-APPNAME' : '*APP ID GOES HERE*',
'GLOBAL-ID' : 'EBAY-US',
'RESPONSE-DATA-FORMAT' : 'JSON',
'REST-PAYLOAD&sortOrder' : 'BestMatch',
'paginationInput.entriesPerPage' : '3',
'outputSelector=AspectHistogram&itemFilter(0).name=Condition&itemFilter(0).value(0)' : results[i].get('itemCondition'),
'itemFilter(1).name=MaxPrice&itemFilter(1).value' : results[i].get('maxPrice'),
'itemFilter(1).paramName=Currency&itemFilter(1).paramValue' : 'USD',
'itemFilter(2).name=MinPrice&itemFilter(2).value' : results[i].get('minPrice'),
'itemFilter(2).paramName=Currency&itemFilter(2).paramValue' : 'USD',
//'itemFilter(3).name=LocatedIn&itemFilter(3).Value' : request.params.itemLocation,
'itemFilter(3).name=ListingType&itemFilter(3).value' : 'FixedPrice',
'keywords' : results[i].get('searchTerm'),
}
});
});
}
Parse.Promise.when(promises).then(function(){
var ebayPingResults = [];
forEach(function(httpResponse) {
var httpResponse = JSON.parse(httpResponse.text);
ebayPingResults.push(httpResponse);
});
response.success(
console.log(ebayPingResults[0]); // So you can see what the response looks like for each httpRequest that was made
)
}, function(err) {
console.log('error!');
response.error('DAMN IT MAN');
});
});
});
据我所知,该括号属于那里。为什么会出现此错误?
答案 0 :(得分:2)
这段代码看起来非常错误:
response.success(
console.log(ebayPingResults[0]); // So you can see what the response looks like for each httpRequest that was made
)
似乎一定是
response.success(function(result) {
console.log(result);
});
答案 1 :(得分:1)
在云代码功能中,代码必须调用response.success()
或response.error()
。其中每个都采用一个可选值,该值将被JSON编码并返回给调用代码。
您当前的代码在完全错误的地方调用console.log()
并破坏代码。
返回anon函数也是错误的。
如果要返回ping结果数组,只需使用以下命令:
response.success(ebayPingResults);
如果您想记录某些内容,请在response.success()
来电之前执行此操作:
console.log(ebayPingResults[0]);
response.success(ebayPingResults);