2

我正在尝试添加用户,但我不断收到此错误:

“发生意外注册异常以下操作:“创建我的应用程序用户”未能执行:只能调用函数 只能调用函数 只能调用函数”

不知道是什么问题...

创建我的应用用户操作

/* globals
$http - Service for AJAX calls 
CONSTS - CONSTS.apiUrl for Backands API URL
Config - Global Configuration
*/
'use strict';
function backandCallback(userInput, dbRow, parameters, userProfile) {

   // When a new user registers, add her to the users object. 
   // If you are using a different object for your users then change this action accordingly. 
   if (parameters.sync)
      return {};
   if (!parameters)
      parameters = {};
   parameters.email = userInput.Username;
   parameters.firstName = userInput.FirstName;
   parameters.lastName = userInput.LastName;
   try{
   var response = $http({
      method: "POST",
      url:CONSTS.apiUrl + "/1/objects/users",
      params: {parameters: {"sync": true}},
      data: parameters,
      headers: {"Authorization": userProfile.token}
   });
}
catch(err) {
   // register user even if there is an error or no users object 
}
   return {};
}
4

1 回答 1

3

Backand cloud 代码运行在一个自定义的 javascript 引擎上,所以它有一些限制。

确保函数之后没有任何代码, 即使在注释中也是如此。

您的操作必须只是功能,上面或下面没有任何代码或注释。

如果要在代码中添加其他函数,可以将其添加为内部函数,如下所示:

function backandCallback(userInput, dbRow, parameters, userProfile) {
   function foo(){
      // do something great
   }

   foo();

   return {};
}
于 2016-04-05T08:52:39.263 回答