无法使用“下划线”来使用parsing服务器
我刚刚迁移了一个分析服务器,除云代码之外,一切正常。 我已经了解到,这是因为在我的main.js中,我需要库“Underscore”。
这是我的云代码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); }); });
代码在迁移之前没有任何错误。 我猜测的要求没有find正确的文件夹。 给你文件夹结构看起来像这样:
Cloudcode位置:mainfolder-> cloud-> main.js
下划线库:mainfolder-> node_modules->下划线(文件夹)
代码是错误的还是文件夹的结构有问题?
提前致谢!
/马丁
你必须指出正确的下划线文件。 我做了以下几点:
var _ = require('../node_modules/underscore/underscore.js')
将下划线添加到package.json
的依赖项中,手动或运行npm install underscore --save
这将导致像这样的一行:
"underscore": "^1.8.3"
从那时起,你可以做到这一点
var _ = require('underscore');