gpt4 book ai didi

javascript - 如何在 Express js 中显示每个 Evernote 笔记的标题?

转载 作者:行者123 更新时间:2023-12-03 07:42:58 25 4
gpt4 key购买 nike

你知道如何在 Express js 中显示所有 Evernote 笔记的标题和内容吗? https://github.com/evernote/evernote-sdk-js/blob/master/sample/express/routes/index.js https://github.com/evernote/evernote-sdk-js/blob/master/sample/express/views/index.jade

500 TypeError: C:\Users\lvcpp\Docs\evernote-sdk-js\sample\express\views\index.jade:31 29| li= session.notebooks[i].name 30| ul > 31| - for (var i = 0; i < session.notesMeta.length;++i) 32| li= session.notesMeta.notes[i].title 33| 34 小时| h2 当前状态无法读取未定义的属性“长度”

29| li= session.notebooks[i].name
30| ul
> 31| - for (var i = 0; i <session.notesMeta.length;++i)
32| li= session.notesMeta.notes[i].title
33|小时
34| h2 当前状态


Express js Web 应用程序:

//index.js:
...

exports.index = function(req, res) {
if(req.session.oauthAccessToken) {
var token = req.session.oauthAccessToken;
var client = new Evernote.Client({
token: token,
sandbox: config.SANDBOX
});
var noteStore = client.getNoteStore();
noteStore.listNotebooks(function(err, notebooks){
req.session.notebooks = notebooks;
res.render('index');
});

var notebook=noteStore.getDefaultNotebook(function (err, notebook){
filter = new Evernote.NoteFilter();
filter.notebookGuid = notebook.guid;
resultSpec = new Evernote.NotesMetadataResultSpec();
resultSpec.includeTitle=true;
noteStore.findNotesMetadata(filter, 0, 100, resultSpec, function(err, notesMeta) {
req.session.notes = notes;
res.render('index');
});
});

} else {
res.render('index');
}
};

//index.jade
...

ul
- for (var i = 0; i < session.notebooks.length; ++i)
li= session.notebooks[i].name
ul
- for (var i = 0; i < session.notesMeta.length; ++i)
li= session.notesMeta.notes[i].title

p.s. Thanks, @conch,
but unfortunately I get another error, after the fixes of code:

500 TypeError: C:\Users\lvcpp\Docs\evernote-sdk-js\sample\express\views\index.jade:31 29| li= session.notebooks[i].name 30| ul > 31| - for (var i = 0; i < session.notesMeta.notes.length; ++i) 32| li= session.notesMeta.notes[i].title 33| hr 34| h2 Current status Cannot read property 'notes' of undefined

29| li= session.notebooks[i].name
30| ul
> 31| - for (var i = 0; i < session.notesMeta.notes.length; ++i)
32| li= session.notesMeta.notes[i].title
33| hr
34| h2 Current status

我们需要在index.js中定义“notes”属性。

但是如何,或者我们真的需要它来处理吗?

在我的控制台 Nodejs 应用程序中,所有事情都可以在没有注释的特殊定义的情况下运行:

function showlistNotes() {
filter = new Evernote.NoteFilter();
resultSpec = new Evernote.NotesMetadataResultSpec();
resultSpec.includeTitle=true;

noteStore.findNotesMetadata(filter, 0, 100, resultSpec, function(err, notesMeta) {
if (err) {
console.error('err',err);
}
else {
console.log("\nFound "+notesMeta.notes.length+" notes in all the notebooks:");

for (var i in notesMeta.notes) {
console.log(i+": "+notesMeta.notes[i].title);
}

console.log('\nGet the contents of the selected note (see full list of notes, from all your notebooks):\nPlease insert the number from 0 to ' + notesMeta.notes.length );
process.openStdin().addListener("data", function(d) {
var a=d.toString().trim();
noteStore.getNote(notesMeta.notes[a].guid, true, true, true, true, function(err, note) {
console.log(err || ENML.PlainTextOfENML(note.content, note.resources) );
});
});
}
});
}

最佳答案

失败是因为您的js文件在noteStore.findNotesMetadata的回调中设置了一个名为notes的 session 变量,但您的jade文件需要一个名为notesMeta的 session 变量。您的 jade 文件也存在索引错误(您不应该迭代 session.notesMeta,您应该迭代 session.notesMeta.notes)。

正确的代码:

index.js

noteStore.findNotesMetadata(filter, 0, 100, resultSpec, function(err, notesMeta) {
req.session.notesMeta = notesMeta;
res.render('index');
});

index.jade

ul
- for (var i = 0; i < session.notesMeta.notes.length; ++i)
li= session.notesMeta.notes[i].title

关于javascript - 如何在 Express js 中显示每个 Evernote 笔记的标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35327980/

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