Cos*_*sta 4 templates couchdb commonjs underscore.js kanso
我一直在寻找各种各样的想法.我正在尝试从couchdb show和list函数生成html页面.我想利用underscore.js的模板解决方案.我要坚持的部分是如何在我的节目和列表功能中包含html模板.
我在哪里存放它们?作为附件?然后我如何在我的节目和列表功能中引用它们.我假设!json和!代码宏没有被使用,我无法弄清楚如何使用常见的js中的require()来实现它.
任何帮助都会摇滚!
谢谢!
额外信息:我正在使用Kanso推送我的应用程序,而不是CouchApp.
根据定义,CouchDB附件在show和list函数中不可访问.
显示和列表功能支持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) }"
}
}
Run Code Online (Sandbox Code Playgroud)
这个视图看起来像这样
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
Run Code Online (Sandbox Code Playgroud)