1
我有一个用JavaScript编写的设计文档(有人写了这个函数)用于一个Cloudant数据库。此功能用于更新文档。在这个文件中,我想先打个电话给JSON.minify,我已经在网上找到一些代码https://www.npmjs.com/package/jsonminify在Cloudant/CouchDB设计文档中调用外部JavaScript函数
更新函数的代码在下面..我想知道如何调用JSON 。根据提供的链接中提供的代码进行分析:JSON.parse(JSON.minify(str));我想使用_ref = JSON.prase(JSON.minify(reqBody));我想要使用_ref = JSON.prase(json.minify(reqBody));
有人能告诉我如何从Cloudant的设计文档中调用此外部代码。 (在大多数情况下Cloudant与CouchDB非常相似,所以我认为它可能是相同的答案)
在此先感谢!
function(doc, req) {
if (!doc) {
return [doc, JSON.stringify({ status: 'failed' })];
}
var reqBody=req.body;
_ref = JSON.parse(reqBody);
for (k in _ref) {
v = _ref[k];
if (k[0] === '/'){
nestedDoc = doc;
nestedKeys = k.split('/');
_ref1 = nestedKeys.slice(1, -1);
for (_i = 0, _len = _ref1.length; _i < _len; _i++){
nestedKey = _ref1[_i];
nestedDoc = ((_ref2 = nestedDoc[nestedKey]) != null ? _ref2 : nestedDoc[nestedKey] = {});
}
k = nestedKeys.slice(-1)[0];
if (v === '__delete__'){
delete nestedDoc[k];
}
continue;
}
if (v === '__delete__'){ delete doc[k]; }
else{ doc[k] = v; } }
return [ doc, JSON.stringify({ status: 'success' }) ];
}
这正是我所需要的。我不知道这是可能的。非常感谢! – Julie