数据库中的列表函数得到一个表达式不会计算为函数错误
list function in couch db getting a expression does not evaluate to a function error
我是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'
相关文章:
- 能够在定义函数表达式之前使用它
- 函数表达式,返回回调函数
- JavaScript中的立即调用函数表达式(IIFE)-传递jQuery
- 函数声明与函数表达式之间的性能差异
- 立即调用函数表达式(IIFE)相对于普通函数的优势
- 如何防止 JS 缩小删除命名函数表达式的名称
- Angularjs 与 coffeescript 函数表达式中断
- JavaScript 混乱中的函数表达式
- 从ES6中的函数表达式访问类作用域
- 提升作为数组项的匿名函数表达式
- Javascript Mocha测试-测试函数表达式中的函数表达式
- 函数中的JavaScript函数表达式
- Javascript闭包覆盖函数表达式
- 函数表达式的词法作用域
- 请解释一下“;立即调用函数表达式“;以及“;自调用匿名函数”;
- JavaScript 中的函数语句和函数表达式
- ng-class 的函数表达式在 ng-click 时被调用
- 如何创建名称和主体存储在不同变量中的 JavaScript 函数表达式
- Object.Prototype 方法和 IIFE(立即调用的函数表达式)中的“use strict”
- 全局范围内的函数表达式与函数声明的区别