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) }"
}
}
这种观点是这样的
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
谢谢!将我的模板编码为字符串正是我想要避免的。接下来我将寻找某种预处理器。 – Costa 2012-04-06 15:23:29
查看/显示**可以**包括任何东西,使用CommonJS。在你的例子中,Kanso(虽然优秀)是无关紧要的。 map函数中的require()发生在CouchDB中。 – JasonSmith 2012-04-07 05:04:07
@JasonSmith这很有趣。这是最近的变化吗?为什么CoichApp包含宏? – Slartibartfast 2012-04-07 06:15:41