node.couchapp.js CouchAppをセットアップし、それをCouchDBにプッシュしました。デフォルトで含まれているSammyとjQueryがあります。テンプレートにMustacheを追加したいのですが、どこにあるのか正確にはわかりません。Node.jsモジュールまたはjQueryプラグインとして使用できます。
動作するかどうかを確認するために、いくつかのサンプルコードから始めましたが、動作しません。
ddoc.lists = {
"basic": "function (head, req) { var that = this; provides('html', function () { var to_html = require('modules/mustache').to_html; var members = []; var row; while (row = getRow()) { members.push({club: row.key[0], name: row.key[1]}); } return to_html(that.templates['roster.mustache'], { members: members }); }) }"
};
結果:
{"error":"invalid_require_path","reason":"Object has no property \"modules\". ...
プロジェクトの構造は次のとおりです。
. Project
| - app.js
| - attachments
| - - scripts
| ` - index.html
| - modules
| | mustache
| - ` - mustache.js
` - templates
更新 コードを少し変更し、考えられる原因としてテンプレートフォルダーを除外しました。このスニペットは、ここSOで解決された質問からのものであるため、実際に機能するはずです。しかし、それでも同じエラーです。npm install mustacheを使用してmustache.jsをインストールし、フォルダーの名前をnode_modulesからmodulesに変更しました(node_modulesでも機能しませんでした)。
"basic": "function (head, req) { provides('html', function () { var template = '{{%IMPLICIT-ITERATOR}}{{name}}: <ul> {{#items}}<li>{{.}}</li>{{/items}} </ul>'; var mustache = require('./modules/mustache/mustache.js'); return mustache.to_html(template,view);});}"
しかし、それでも同じエラーです。