Mustache section in Couchdb issues

≡放荡痞女 提交于 2019-12-08 11:24:08

问题


I am a couchdb newbie running CouchDB 1.0.1.

I have a very basic issue. I cannot get Mustache Sections to render in a list. Here is my list with the data hard coded from an example.

function(head, req) {
    start({
        "headers": {
            "Content-Type": "text/html"
        }
    });
var mustache = require("lib/mustache");
var view = {name: "Joe's shopping card",items: ["bananas", "apples"]};
var template = "{{name}}: <ul> {{#items}}<li>{{.}}</li>{{/items}} </ul>";
return mustache.to_html(template,view);

Outputs:

Joe's shopping card: <ul> <li></li><li></li></ul>

Please help!!!

Thank you, / Jeff


回答1:


Oh barf, I just figured it out and it is a little rediculous. Here it is for anyone else who wants to save some time. Add this to your template "{{%IMPLICIT-ITERATOR}}".

So:

var template = "{{name}}: <ul> {{#items}}<li>{{.}}</li>{{/items}} </ul>";

Becomes:

var template = "{{%IMPLICIT-ITERATOR}}{{name}}: <ul> {{#items}}<li>{{.}}</li>{{/items}} </ul>";


来源:https://stackoverflow.com/questions/4394595/mustache-section-in-couchdb-issues

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!