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

时间:2016-02-10 23:23:12

标签: javascript node.js express evernote

你知道如何显示标题& 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 app:

// 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。谢谢,@ conch,
但不幸的是我收到了另一个错误   代码的修复:

     

500 TypeError:   C:\ Users \用户lvcpp \文档\的Evernote-SDK-JS \样品\表达\视图\ index.jade:31   29 | li = session.notebooks [i] .name 30 | ul&gt; 31 | - for(var i = 0; i&lt;   session.notesMeta.notes.length; ++ i)32 |李=   session.notesMeta.notes [i] .title 33 |小时34 | h2当前状态不能   读取未定义的属性'notes'

     

29 | li = session.notebooks [i] .name
30 | ul
&gt; 31 | - for(var i =   0;我&lt; session.notesMeta.notes.length; ++ i)
32 |李=   session.notesMeta.notes [i] .title
33 | hr
34 | h2当前   状态

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

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

在我的控制台nodejs app中,所有操作都没有笔记的特殊定义:

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)  );
        }); 
      }); 
    }
  });
}

1 个答案:

答案 0 :(得分:1)

它失败了,因为你的js文件在noteStore.findNotesMetadata的回调中设置了一个名为<table border="0" cellspacing="0" cellpadding="0" style="table-layout: fixed;margin: 0px auto;"> 的会话变量,但是你的jade文件期望一个名为notes的会话变量。你的jade文件也有一个索引错误(你不应该遍历notesMeta,你应该迭代session.notesMeta)。

正确的代码:

<强> index.js

session.notesMeta.notes

<强> index.jade

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