数据库中的列表函数得到一个表达式不会计算为函数错误

list function in couch db getting a expression does not evaluate to a function error

本文关键字:函数 表达式 一个 计算 错误 列表 数据库      更新时间:2023-09-26

我是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;});})"}

我想知道函数有什么问题,谢谢

您需要调用:

while (row = getRow()){

代替:

while (row === getRow()){

并且引号内的换行符需要转义:

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