From b00c3080b801d187bc355015aadc48e235230ec4 Mon Sep 17 00:00:00 2001 From: life Date: Sat, 14 Mar 2015 14:44:15 +0800 Subject: [PATCH] =?UTF-8?q?fixConflict=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当是第一个笔记时, inchangeNoteid=curNoteId 此时, 冲突, 会去服务器上拿数据->contentSynced -> 返回到前台, 虽然curNoteId != noteId, 但是inChangeNoteId=noteId, 于是reRenderNote 导致内容不符. 解决方法, 设置curNoteId时把inChangeNoteId清空 --- node_modules/note.js | 2 +- public/js/app/note.js | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/node_modules/note.js b/node_modules/note.js index 7ec6fcb4..24872935 100644 --- a/node_modules/note.js +++ b/node_modules/note.js @@ -120,7 +120,7 @@ var Note = { if(isDirty) { console.error("NONO----------"); - Web.alertWeb("NONO"); + // Web.alertWeb("??NONO"); } updates['LocalIsDelete'] = false; updates.UpdatedTime = date; diff --git a/public/js/app/note.js b/public/js/app/note.js index 6939b2cd..94681c49 100644 --- a/public/js/app/note.js +++ b/public/js/app/note.js @@ -642,6 +642,10 @@ Note.changeNoteForPjax = function(noteId, mustPush, needTargetNotebook) { Note.contentAjax = null; Note.contentAjaxSeq = 1; Note.inChangeNoteId = ''; +Note.setCurNoteId = function(noteId) { + Note.curNoteId = noteId; + Note.inChangeNoteId = ''; +}; Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) { var self = this; @@ -740,6 +744,9 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) { // 重新渲染笔记, 因为sync更新了 Note.reRenderNote = function(noteId) { var me = this; + + console.error("???") + me.showContentLoading(); var note = Note.getNote(noteId); Note.renderNote(note); @@ -846,7 +853,8 @@ Note.renderNoteContent = function(content) { setEditorContent(content.Content, content.IsMarkdown, content.Preview); // 只有在renderNoteContent时才设置curNoteId - Note.curNoteId = content.NoteId; + Note.setCurNoteId(content.NoteId); + // life // 重新渲染到左侧 desc, 因为笔记传过来是没有desc的 content.Desc = Note.genDesc(content.Content); @@ -1133,7 +1141,7 @@ Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) { Note.renderNote(note); Note.renderNoteContent(note); - Note.curNoteId = note.NoteId; + Note.setCurNoteId(note.NoteId); // 更新数量 Notebook.incrNotebookNumberNotes(notebookId) @@ -1954,6 +1962,8 @@ Note.contentSynced = function(noteId, content) { if(me.curNoteId == noteId || me.inChangeNoteId == noteId) { // alert(note.Title); // 重新渲染 + // alert(me.curNoteId == noteId); false + // alert(me.inChangeNoteId == noteId); true Note.reRenderNote(noteId); } else { // 生成desc @@ -2707,7 +2717,7 @@ Note.fixSyncConflict = function(note, newNote) { // 如果当前编辑的是这个笔记, 那切换到newNote上来 if(Note.curNoteId == note.NoteId) { - Note.curNoteId = newNote.NoteId; + Note.setCurNoteId(newNote.NoteId); } };