gpt4 book ai didi

javascript - map 函数保存后不执行

转载 作者:行者123 更新时间:2023-11-30 18:02:33 26 4
gpt4 key购买 nike

我正在使用 chouchdb 1.3.0 创建以下 map 函数。如果我将它作为临时 View 运行,它工作正常,但一旦我保存它,它就无法编译。

function(doc) {
var datestamp = convert_date(doc["report"]["period"]);
var report_suite = doc["report"]["reportSuite"]["id"];
var segment = doc["report"]["segment_id"];
emit([report_suite, segment, datestamp], [doc["report"]["elements"][0]["id"]]);
}

function convert_date(date){
var months = {"Jan": "01", "Feb": "02", "Mar": "03", "Apr": "04", "May": "05", "Jun": "06", "Jul": "07", "Aug": "08", "Sep": "09", "Oct": "10", "Nov": "11", "Dec": "12" };
var year = date.substring(13, 17);
var month = months[date.substring(8,11)];
var day = date.substring(5,7).replace(" ", "0");
var datestamp = year + month + day;
return datestamp;
}

错误信息是:“表达式不计算为函数”

我用谷歌搜索并尝试失败:

  • 在函数两边加上括号
  • 内联 convert_date 函数

最佳答案

如果将 convert_date 函数放在 map 函数中会怎样?

  function(doc) {
var convert_date = function(date) {
var months = {"Jan": "01", "Feb": "02", "Mar": "03", "Apr": "04", "May": "05", "Jun": "06", "Jul": "07", "Aug": "08", "Sep": "09", "Oct": "10", "Nov": "11", "Dec": "12" };
var year = date.substring(13, 17);
var month = months[date.substring(8,11)];
var day = date.substring(5,7).replace(" ", "0");
var datestamp = year + month + day;
return datestamp;
}
var datestamp = convert_date(doc["report"]["period"]);
var report_suite = doc["report"]["reportSuite"]["id"];
var segment = doc["report"]["segment_id"];
emit([report_suite, segment, datestamp], [doc["report"]["elements"][0]["id"]]);
}

关于javascript - map 函数保存后不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16583423/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com