我一直在到处寻找,试图找出这个问题。我正在尝试从 couchdb show 和 list 函数生成 html 页面。我想利用 underscore.js 的模板解决方案。我遇到的问题是如何在我的显示和列表函数中包含 html 模板。
我把它们存放在哪里?作为附件?然后我如何在我的显示和列表函数中引用它们。我假设 !json 和 !code 宏没有被使用,并且我不知道如何使用常见 js 中的 require() 来做到这一点。
任何帮助都会很棒!
谢谢!
额外信息:我使用 Kanso 来推送我的应用程序,而不是 CouchApp。
最佳答案
根据定义,CouchDB 附件是 not accessible in show and list functions .
显示和列表功能支持 CommonJS。因此,您只需在设计文档中包含任何库即可。
{ "_id": "_design/example"
, "say_hi": "module.exports = function(person) { return 'Hello, ' + person }"
, "shows":
{ "hello": "function(doc, req) { var hi = require('say_hi'); return hi(req.query.me) }"
}
}
这个 View 看起来像这样
GET /my_db/_design/example/_show/hello?me=Jason
HTTP/1.1 200 OK
Server: CouchDB/1.2.0 (Erlang OTP/R15B)
Date: Fri, 06 Apr 2012 11:02:33 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 12
Hello, Jason
关于templates - 如何在 CouchDB 中使用 html 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10039623/