我刚刚迁移了一个 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(error) {
response.error(error);
});
});
代码在迁移之前没有错误。我猜 require 找不到正确的文件夹。给你的文件夹结构看起来像这样:
云代码位置: mainfolder->cloud->main.js
下划线库: mainfolder->node_modules->underscore(文件夹)
是代码有问题还是文件夹结构有问题?
提前致谢!
/马丁
最佳答案
您必须指向正确的下划线文件。我做了以下事情:
var _ = require('../node_modules/underscore/underscore.js')
关于javascript - 无法让 'underscore' 与解析服务器一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35382451/