简体   繁体   English

使用common.js模式在沙发视图中重用功能

[英]Reuse of functions across couchdb views using commonjs pattern

There are a number of functions I want to use across various couchdb view map functions. 我想在各种beddb视图图函数中使用许多函数。 I am trying to use the commonjs require pattern. 我正在尝试使用commonjs require模式。

Using the following design doc why does the test1 require statement work whereas the test2 require statement does not seem to work ? 使用以下设计文档,为什么test1 require语句有效,而test2 require语句似乎无效?

How else can I reuse functions across multiple couchdb views ? 我还能如何在多个beddb视图之间重用函数?

{
    "_id": "_design/app",
    "_rev": "29-876296b1278db067378635a5f3309aa3",
    "views": {
       "test1": {
           "map": "function (doc) {\n  var setting1 = require('views/lib/config').setting1;\n    emit(doc._id, setting1);\n  }"
       },
       "test2": {
           "map": "function (doc) {\n  var fn1 = require('views/lib/sharedFunctions').fn1;\n    emit(doc._id, fn1(doc));\n  }"
       },
       "lib": {
           "config": "exports.setting1 = 'a';exports.setting2 = 42",
           "sharedFunctions":"exports.fn1 = function (doc) {\n   return 'fn1 read doc ' + doc._id;\n }"
       }
    }
}

further info: I am currently using the 'grunt-couchapp' plugin for managing the uploading of my design docs from my project src directories 进一步的信息:我目前正在使用'grunt-couchapp'插件来管理从我的项目src目录上传我的设计文档

Just adding this as the answer so that this question stops appearing unanswered. 只需将其添加为答案,即可停止出现未回答的问题。 The OP found that upgrading to 1.3 (from 1.2) fixed the problem. OP发现升级到1.3(从1.2)解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM