2014-06-17 36 views
-1

我嘗試部署我的代碼解析,我不斷收到一個錯誤,指出:承諾的功能,給「語法錯誤:意外的令牌}」

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'); 
      }); 
    }); 
}); 

至於I K現在,該支架屬於那裏。爲什麼會發生此錯誤?

+0

這」不是個:

response.success(ebayPingResults); 

如果你想記錄的東西,你response.success()呼叫之前做(普通的javascript的forEach(函數(httpResponse){'。是否有一些庫使它工作? – jfriend00

+0

當你解決了直接的問題,仍然有一些基本的東西需要解決這個代碼。 promises.push(function(){...})'會給你一個函數數組ns,而不是承諾數組 - 我希望你想'promises.push(Parse.Cloud.httpRequest({...})'。 (2)'forEach()'是一個數組方法,例如'myArray.forEach(fn)'。我期望理解和掌握'request'和'response'對象是關鍵。 –

回答

1

在雲代碼的功能,代碼必須調用要麼response.success()response.error()。它們中的每一個都採用可選值,該值將被JSON編碼並返回給調用代碼。

您當前的代碼是在完全錯誤的地方調用console.log(),並破壞了代碼。

返回anon函數也是不正確的。

如果你想返回平的結果的陣列,只需使用下列內容:

console.log(ebayPingResults[0]); 
response.success(ebayPingResults); 
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); 
}); 
+0

似乎可以解決語法問題,但它現在說'沒有調用成功/錯誤'。任何想法爲什麼? – Ghobs

+0

@Ghobs:「它」說的是什麼? – zerkms

+0

解析日誌,當我試圖從我的iOS應用程序調用函數。 – Ghobs

相關問題