简体   繁体   English

如何在Meteor-ShareJS ace编辑器中获取当前文本

[英]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(); 返回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. 查看您的代码,很显然getValue()在DOM有机会进行反应性更新之前就已经在运行,因此它总是获取先前选择的值。 You need to wrap that line in a Tracker.afterFlush: 您需要将该行包装在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. {{#with docId}} ,我不确定为什么将{{document}}包裹在{{#with docId}} ,似乎可能期望在Documents对象中使用document属性。 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. 不知道这是否真正影响到任何东西,但是当您直接从编辑器中提取document ,这有点令人困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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