- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在运行一段简单的代码,如下所示。
基本上我想读取“notes-data.json”中已有的数据,然后将其附加。
node notes.js
console.log('Starting notes.js');
const fs = require('fs');
var addNote = (title, body) => {
var notesString = fs.readFileSync('playground/notes-data.json');
var notes;
notes = JSON.parse(notesString);
var note = {
title,
body
};
notes.push(note);
fs.writeFileSync('playground/notes-data.json', JSON.stringify(note));
};
addNote("Hi", "There");
module.exports = {
addNote: addNote
};
预期:当我运行此程序时,它必须添加“Hi There”。
实际:出现以下错误。
(base) prakashp:newproject2 prakashp$ node notes.js
Starting notes.js
/Users/prakashp/training/nodejs/practise/newproject2/notes.js:13
notes.push(note);
^
TypeError: notes.push is not a function
at addNote (/Users/prakashp/training/nodejs/practise/newproject2/notes.js:13:11)
at Object.<anonymous> (/Users/prakashp/training/nodejs/practise/newproject2/notes.js:18:1)
at Module._compile (internal/modules/cjs/loader.js:721:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
at executeUserCode (internal/bootstrap/node.js:499:15)
at startMainThreadExecution (internal/bootstrap/node.js:436:3)
如果我评论以下行,我不会收到任何错误。
notes = JSON.parse(notesString);
请帮忙。
最佳答案
你的 json 文件应该有一个数组。这是您尝试在 repl
站点上运行的工作代码。在 JSON 解析之后,您的变量需要是一个数组,以便您可以对其使用 push
方法。
我还发现了一个错误,您不应该将 note
保存到 json 文件中,而应该保存 notes
。因为您将再次将对象覆盖到文件中,并且将导致应用程序再次崩溃。使用下面的行。
fs.writeFileSync('playground/notes-data.json', JSON.stringify(notes));
关于node.js - TypeError : notes.推送不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56345640/
我已经创建了一个扩展库组件,但我的 XPage 扩展库正在我的本地 Notes 浏览器上运行。如果我在notes 中运行我的XPage,它运行良好。 当我在浏览器中运行它时,出现以下错误: Canno
我正在学习 React 教程,作者有一些代码如下: 但是,如果您只是这样做,同样的代码也可以工作:
我使用一个简单的 Action 代理创建了一个自动回复代理,它当前响应所有发件人,我只想将回复发送给一组特定的发件人。 这是我想要实现的一个例子: 我有一个 Lotus Notes 邮件数据库,电子邮
我有一个要求,其中有一个带有附件的文档,当我点击一个按钮时,它会打开一个新表单。此表单必须在富文本字段中包含该附件。我在打开的新表单的 PostOpen 事件中编写了以下代码 Set item
我在 Windows 7 上使用 Lotus Notes 8.5.2。我想创建一个自定义 View 来显示除已发送邮件之外的所有电子邮件。换句话说,它包含:收件箱和所有文件夹。 目前我的 ALL DO
我正在设置一个 Lotus Notes 帐户来接受来自客户端的电子邮件,并自动将每封电子邮件保存为纯文本文件以供其他应用程序处理。 因此,我正在尝试在 Lotus 中创建我的第一个代理,以自动将电子邮
有没有不用付费软件就可以解锁 Lotus Notes 数据库设计的方法? 锁定数据库的人离开了公司,我们没有此应用程序的任何模板。因此,只有通过解锁此数据库才能开始进一步开发此数据库。 最佳答案 您是
我正在用 Lotus Notes 6.0.3(即将升级到 8.5)设计一个工作流数据库,我的操作系统是 Windows XP。 我最近尝试将选项卡式表格转换为可编程表格。这样我就可以控制在打开时向用户
我尝试在 Lotus Notes 中构建高级表单。某些字段应根据其他字段的状态隐藏。 我可以通过定义一个公式来隐藏一个字段。但问题是我必须首先保存文档,关闭它然后重新打开它才能看到字段被隐藏。 当我更
我在服务器 1 中有一个数据库,它引用服务器 2 中的多个数据库用于记录验证目的。当计划的代理运行时,它遇到“对象变量未设置”错误。但是,当我尝试手动运行代理(右键单击代理名称,单击运行)时,它运行顺
在 Lotus Notes 数据库上启用源代码控制很容易 - 这将维护数据库中所有设计元素的磁盘副本。但是,是否也可以包含文档?在我们的设计中,我们在数据库中的 Lotus Notes 文档中存储了大
我想以编程方式解密 Lotus Notes NSF 文件。假设对于每个 NSF,我都有访问 NSF 所需的 ID 文件和密码。 我使用的是 Lotus Notes 8.5.2,Windows 7 SP
我正在使用 Lotus Notes 数据库,我们整个公司都将其客户数据添加到其中。搜索功能应该为我提供客户,当我单击它时,我会获得日常工作所需的更详细信息。 但是,我必须搜索这个数据库,它在显示数据方
我的要求是收集 Lotus Notes 文档,对于给定的一组搜索词,这些文档包含: 所有这些条款, 这些条款中的任何一个 或没有这些条款。 我正在使用 Database.FTsearch(...)方法
我试图在我们的网站上设置 mailto。 我写了如下代码 mail us 当有人按下“向我们发送邮件”链接时,在 Lotus Notes 中,文本会直接出现在电子邮件地址所在的位置。 mail.us.
莲花 8.5.3 我需要做的是启动外部流程以响应符合特定条件的传入电子邮件。 规则无法做到这一点。很公平,看起来代理可以。 好的,所以设置一个带有代理的 LotusScript 来做我需要的,用运行测
在我的 Lotus Notes 代理中,我使用新表单临时创建了一些文档(表单中有一个富文本字段),在代码的末尾,我有“Call TempDoc.Remove(True)”,当程序执行这行代码,出现错误
我正在编写向用户发送邮件的代码。邮件文本包含日期。虽然日期计算正确,但日期仍以英语显示,即使所有用户都使用德语 Windows 操作系统并且在 Notes 首选项中将德语设置为他们的语言。这是我的代码
我们正在服务台团队中与 Lotus Notes 合作,了解我们回复消息需要多长时间会很有用。有什么办法可以实现这一点吗? 最佳答案 建议方法的问题在于,它们仅测量某人开始撰写响应之前的时间,而不是发送
我们正在服务台团队中与 Lotus Notes 合作,了解我们回复消息需要多长时间会很有用。有什么办法可以实现这一点吗? 最佳答案 建议方法的问题在于,它们仅测量某人开始撰写响应之前的时间,而不是发送
我是一名优秀的程序员,十分优秀!