在沙发中使用list函数获取表达式不会计算函数错误

时间:2014-06-10 01:14:49

标签: javascript couchdb

我是couchdb的新手我从couchdb wiki复制并粘贴了一个简单的列表函数,我是 获取表达式不会在我的浏览器中评估函数错误这是我在沙发中的代码我包含了整个文档

    {
   "_id": "_design/recipies",
   "_rev": "44-58a0833eb8834e801ca23f6fc82c2a6a",
   "language": "javascript",
   "views": {
       "cup": {
           "map": "function(doc) {\n\tif(doc.ingredients){\n\t\tfor (ingredient in doc.ingredients){\n\t\t\tif(doc.ingredients[ingredient].cup){\n\t\t\t\tvalue = ingredient;\n\t\t\t\tkey = doc.ingredients[ingredient].cup;\nemit(key, value);}\n\t\t}\n\t}\n\n\n  \n}"
       }
   },
   "lists": {
       "index-posts": "function(doc, req) {provides('html', function() {var html = '<html><body><ol>\n'; while (row === getRow()) { html += '<li>' + row.key + ':' + row.value + '</li>\n';} html += '</ol></body></head>';return html;});}"
   }
}

这是我在浏览器中收到的错误

{"error":"compilation_error","reason":"Expression does not eval to a function. (function(doc, req) {provides('html', function() {var html = '<html><body><ol>\n'; while (row === getRow()) { html += '<li>' + row.key + ':' + row.value + '</li>\n';} html += '</ol></body></head>';return html;});})"}

我想知道感谢

的功能有什么问题

1 个答案:

答案 0 :(得分:2)

您需要致电:

while (row = getRow()){

而不是:

while (row === getRow()){

引用字符串中的换行符需要转义:

'<li>' + row.key + ':' + row.value + '</li>\\n'