无法使用“下划线”与分析服务器一起使用 [英] Can't get 'underscore' to work with parse server
问题描述
我刚刚迁移了一个Parse Server,除云代码外,其他所有工作都正常。我已经了解到,这是因为在我的main.js中,我需要库Underscore。
这是我的云代码函数:
Parse.Cloud.define(ReadyUp,function(request,response){
var _ = require('underscore');
var fbid = request.user.get(fbid);
var query = new Parse.Query(Spel);
query.equalTo(lobby,fbid);
query.find()。then(function(results){
_.each(results,function(spel){
spel.addUnique(ready,fbid);
});
return Parse.Object.saveAll(results);
})。then(function(result){
response.success(result);
},function错误){
response.error(error);
});
});
代码在迁移之前没有错误。我猜这个require不能找到正确的文件夹。为了给你文件夹结构,它看起来像这样:
Cloudcode位置:
mainfolder-> cloud-> main.js
下划线库:
mainfolder-> node_modules->下划线(文件夹)
代码有问题或文件夹结构有问题吗?
预先感谢!
/ Martin
你必须指向正确的下划线文件。我做了以下操作:
$ $ p $ var _ = require('../ node_modules / underscore / underscore.js')
I just migrated a Parse Server, and everything works, except cloud code. I have come to the understanding that it's because in my main.js I require the library "Underscore".
This is my cloud code function:
Parse.Cloud.define("ReadyUp", function(request, response) {
var _ = require('underscore');
var fbid = request.user.get("fbid");
var query = new Parse.Query("Spel");
query.equalTo("lobby", fbid);
query.find().then(function(results) {
_.each(results, function(spel) {
spel.addUnique("ready", fbid);
});
return Parse.Object.saveAll(results);
}).then(function(result) {
response.success(result);
}, function(error) {
response.error(error);
});
});
The code worked with no error before the migration. I'm guessing the require doesn't find the right folder. To give you folder structure it looks like this:
Cloudcode location: mainfolder->cloud->main.js
Underscore library: mainfolder->node_modules->underscore(folder)
Is the code faulty or is the structure of folders faulty?
Thanks in advance!
/Martin
You have to point to correct underscore file. I did the following:
var _ = require('../node_modules/underscore/underscore.js')
这篇关于无法使用“下划线”与分析服务器一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!