Php 更改ShareJS中的默认文本

Php 更改ShareJS中的默认文本,php,mysql,node.js,redis,share.js,Php,Mysql,Node.js,Redis,Share.js,情境:我有一个用PHP和mySQL编写的网站,用于创建/共享文档。现在我需要向网站添加一些协作功能,以便使用shareJS(使用默认ace编辑器) 几乎所有的工作都很好,但我不能在编辑器中设置默认文本,因为它从默认的redis数据库获取数据。是的,我可以尝试在redis DB中重写数据,或者用mySQL DB更改数据,但我想逃避它 在客户端部分,我尝试删除所有文本并设置新的 // delete text which come from node server var nodeText = doc

情境:我有一个用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:{一些垃圾,由上面的输入和代码生成}


可能我做得不对。

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

doc.attach_ace(editor, true);
第二个变量表示保留编辑器内容,以便您可以在编辑器中设置自己的文本

希望这会有用