简体   繁体   中英

How to get the current text in meteor-sharejs ace editor

Im trying to make a little markdown editor with a panel that shows the rendered markdown. My problem is dont seem to be able to get the current content, it always one step behind. Ive used

return ace.edit("editor").getValue();

Is there a way to bind to the object that the editor is using?

Looking at your code, it seems pretty clear that the getValue() is running before the DOM has a chance to update reactively, so it's always grabbing the value that was previously selected. You need to wrap that line in a Tracker.afterFlush:

document: function () {
  Tracker.afterFlush(function(){
    return ace.edit("editor").getValue();
 });
}

Hopefully that will get things working! As an aside, I'm not sure why you are wrapping the {{document}} in {{#with docId}} , seems like it might be expecting a document property in the Documents object. Not sure if this is actually affecting anything, but seeing as you are directly pulling the document from the editor, it's a little confusing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM