2015-10-19 101 views
0

我認爲我誤解了.play()函數中的某些內容。我花了好幾天的時間試圖弄清楚這一點。Parse.Cloud.play找不到函數

我有一個main.js函數的定義設置。

var pvp_module = require('cloud/otherCode.js'); 
function pushBattleMessage_sum(request, response) 
{ 
    pvp_module.PushNotification_BattleMessageExport(request, response); 
} 

Parse.Cloud.define("PushNotification_BattleMessage", pushBattleMessage_sum); 

這將它發送到另一個運行代碼的othercode.js。在該代碼中,我需要調用第二個雲功能。

function PushNotification_BattleMessage(request, response) 
{ 

    Parse.Cloud.run("push_httpRequest",{request}, 
    { 
     sucess: function(results) 
     { 
      response.success(results); 
     }, 
     error: function(error) 
     { 
      response.error(error); 
     } 
    }); 
} 

第二雲功能在main.js定義回來,我在網上找到

Parse.Cloud.define('push_httpRequest',function(request) 
{ 
    Parse.Cloud.httpRequest(
    { 
    url: 'http://www.parse.com/', 
    success: function(httpResponse) 
    { 
     console.log(httpResponse.text); 
    }, 
    error: function(httpResponse) 
    { 
     console.error('Request failed with response code ' + httpResponse.status); 
    } 
    }); 
}); 

一切都告訴我,這應該是工作,但在我的testharness HTML我總是收到錯誤「未捕獲ReferenceError:push_httpRequest未定義「

此代碼的目的是Android需求狀態,推送通知圖標必須是黑色和白色。我無法使用服務器端解析來初始化這種更改,因此我們通過httpRequest爲GCM設備提供了推送通知。如果我可以讓我的第一個雲功能找到第二個,我應該可以將所有這些都集中在一起。

回答

0

據我在文檔中看到的,define方法的Parse.Cloud對象需要一個函數,它應該有兩個參數。您的功能push_httpRequest然後未正確定義。來自Parse documentation

define(name, func)

Defines a Cloud Function.

Available in Cloud Code only. Parameters:

  • name <String> The name of the Cloud Function
  • func <Function>
    The Cloud Function to register. This function should take two parameters a Parse.Cloud.FunctionRequest and Parse.Cloud.FunctionResponse