2013-03-03 138 views
1

嘿,我使用Parse作为我的后端,我喜欢它,但我有afterSave钩子的问题。解析云代码afterSave不工作

这里是我使用的代码:

Parse.Cloud.afterSave ("JGZwoelf",function (request) { 

         Parse.Push.send({ 
             //Selecting the Channel 
             channels: [ request.object.get('JGZwoelfPush') ], 

              data: { 
              //Selecting the Key inside the Class 
              alert: request.object.get('AusfallInfo') 

              } 
             }, { 
              success: function() { 
              //Push was send successfully 
              }, 

              error: function (error) { 
              //Handle error 
              throw "Got an error" + error.code + " : " + error.message; 
              } 


             }); 
         }); 

每次登录控制台告诉我:结果:

未捕获得到了一个error112:缺少通道名称。

我只是不明白什么是错的!它必须在该JavaScript代码中。如果我进入推送通知手动一切正常:/

编辑: 的部分Parse.Push.send应该是这样的:

Parse.Push.send ({ 
     //Selecting the already existing Push Channel 
     channels: ["JGAchtPush"], //This has to be the name of your push channel!! 
     data: { 
      //Selecting the Key inside the Class 
      alert: request.object.get ("AusfallInfo") 
     } 
    }, { 
     success: function() { 
      //Push was sent successfully 
      //nothing was loged 
     }, 
     error: function (error) { 
      throw "Got and error" + error.code + " : " + error.message; 
     } 
    }); 

通道名称必须是这样的[“exampleChannel” ]。

预先感谢任何帮助:)

回答

3

的第一个参数afterSave应该是一个类名,而不是对象ID。

1

以下是针对新人(和我一样),它与原始问题完全相同的代码,再加上一些评论,加上从接受的答案更正。目的是为了展示少量代码需要更改的示例,以便在您的解析云代码中工作。谢谢Constantin Jacob和bklimt。

Parse.Cloud.afterSave ("UserVideoMessage",function (request) { // name of my parse class is "UserVideoMessage" 

    Parse.Push.send ({ 
     //Selecting the already existing Push Channel 
     channels: ["admin"], //This has to be the name of your push channel!! 
     data: { 
      //Selecting the Key inside the Class, this will be the content of the push notification 
      alert: request.object.get ("from") 
     } 
    }, { 
     success: function() { 
      //Push was sent successfully 
      //nothing was loged 
     }, 
     error: function (error) { 
      throw "Got and error" + error.code + " : " + error.message; 
     } 
    }); 

});