error = "TypeError: Object [object Object] has no method 'addUnique'\n at main.js:33:12";云
Posted
技术标签:
【中文标题】error = "TypeError: Object [object Object] has no method \'addUnique\'\\n at main.js:33:12";云代码解析.com【英文标题】:error = "TypeError: Object [object Object] has no method 'addUnique'\n at main.js:33:12"; Cloud code parse.comerror = "TypeError: Object [object Object] has no method 'addUnique'\n at main.js:33:12";云代码解析.com 【发布时间】:2014-12-08 22:51:38 【问题描述】:我确信这个问题的答案很简单,但我想不通......
这是我在 Cloud Code 中的代码:
Parse.Cloud.define("acceptFriendRequest", function(request, response)
Parse.Cloud.useMasterKey();
var query = new Parse.Query("_User");
var userFrom = new Parse.User();
userFrom = query.get(request.params.userFrom);
console.log(userFrom);
var userTo = new String();
userTo = request.params.userTo;
userFrom.addUnique("friend", userTo);
user.save().then(function (user)
response.success();
, function (error)
console.log(error);
response.error(error);
);
response.success();
);
这是我在 ios 中的代码:
[PFCloud callFunctionInBackground:@"acceptFriendRequest"
withParameters:@@"userFrom":userFrom.objectId,
@"userTo":[PFUser currentUser].objectId
block:^(id object, NSError *error)
if (error)
NSLog(@"Error: %@ %@", error, [error userInfo]);
];
但我收到了错误:
error = "TypeError: Object [object Object] has no method 'addUnique'\n at main.js:33:12";
我也尝试了简单的userFrom.add()
方法,但出现了同样的错误!
谁能帮忙?
【问题讨论】:
您需要重写云代码。userFrom
和userTo
的数据类型是什么?
【参考方案1】:
您需要等待 get 返回对象。我相信 get()
本身只是返回 null。
query.get(request.params.userFrom,
success: function(object)
userFrom = object;
userFrom.addUnique("friend", userTo);
user.save();
,
error: function(object, error)
// something went wrong
);
【讨论】:
【参考方案2】:那些 sdk 方法返回承诺,并且指针列必须填充对象,而不是您必须传递的 id。因此,您需要同时获取用户并像这样链接异步调用...
Parse.Cloud.useMasterKey();
var userFrom; // so it's available in the second 'then' closure
Parse.Query(Parse.User).get(request.params.userFrom).then(function(user)
console.log(user);
userFrom = user;
return Parse.Query(Parse.User).get(request.params.userTo);
).then(function(userTo)
userFrom.addUnique("friend", userTo);
return userFrom.save();
).then(function (user)
response.success(user);
, function (error)
console.log(error);
response.error(error);
);
【讨论】:
以上是关于error = "TypeError: Object [object Object] has no method 'addUnique'\n at main.js:33:12";云的主要内容,如果未能解决你的问题,请参考以下文章
vue踩坑记录3“Error in render: "TypeError: Cannot read property '0' of undefined"”渲染
[Vue warn]: Error in render: "TypeError: Cannot read property 'length' of null"
[Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined
Echarts 明明和官方文档配置一致,图表加载却是报错:Error in mounted hook: "TypeError: Cannot read property 'get
vue中 Error in mounted hook: "TypeError: __WEBPACK_IMPORTED_MODULE_0__assets_swiper_js__.default
el-date-picker日期选择器 ——[Vue warn]: Error in render: "TypeError: date.getFullYear is not a functi