更改ShareJS中的默认文本

时间:2015-09-02 13:10:12

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

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

几乎所有工作正常但我无法在编辑器中设置默认文本,因为它从默认的redis数据库中获取数据。是的,我可以尝试在redis数据库中重写数据或者通过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:{一些垃圾,由上面的输入和代码制作}

Mabe我是以错误的方式做到的。

1 个答案:

答案 0 :(得分:0)

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

doc.attach_ace(editor, true);

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

希望这会有用。

相关问题