【问题标题】:Change default text in ShareJS更改 ShareJS 中的默认文本
【发布时间】:2015-11-28 00:27:30
【问题描述】:

情况:我有网站,用 PHP 和 mySQL 编写,用于创建/共享文档。现在我需要在网站上添加一些协作功能,所以决定使用 shareJS(使用默认的 ace 编辑器)。

几乎所有工作正常,但我无法在编辑器中设置默认文本,因为它从默认 redis 数据库中获取数据。是的,我可以尝试重写redis DB中的数据或通过我的mySQL DB更改它,但我想转义它。

在客户端部分我尝试删除所有文本并设置新的

// delete text which come from node server
var nodeText = doc.getText();
var nodeTextRows = nodeText.split("\n");
nodeTextRows.forEach(function(text, i, arr) {
    var locIDX = i+1;
    doc.del(locIDX, text.length);
    console.log("Delete: " + locIDX + " " + text + " " + text.length);
});


// insert text from DB into editor
var textRows = text.split("\n");
textRows.forEach(function(text, i, arr) {
    var locIDX = i+1;
    doc.insert(locIDX, text);
    console.log("Insert: " + locIDX + " " + text);
});

但是由于这个shareJS代码它不起作用

if editorText != otText
    console.error "Text does not match!"
    console.error "editor: #{editorText}"
    console.error "ot: #{otText}"
    # Should probably also replace the editor text with the doc snapshot.
, 0

所以我的错误信息是: 文字不匹配 编辑器:{空字符串} ot: {一些垃圾,由上面的输入和代码产生}

也许我做错了。

【问题讨论】:

    标签: php mysql node.js redis share.js


    【解决方案1】:

    这是我在源代码中找到的未记录函数:

    doc.attach_ace(editor, true);
    

    第二个变量表示保留编辑器内容,以便您可以在编辑器中设置自己的文本。

    希望对你有用。

    【讨论】:

      猜你喜欢
      • 2011-06-30
      • 1970-01-01
      • 2013-07-16
      • 2013-02-25
      • 1970-01-01
      • 2020-04-13
      • 2015-06-09
      • 1970-01-01
      相关资源
      最近更新 更多