php - 更改 ShareJS 中的默认文本

标签 php mysql node.js redis share.js

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

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

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

// 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);

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

希望这些有用。

关于php - 更改 ShareJS 中的默认文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32354126/

相关文章:

php - Zend SOAP : Change the default array element name "item" to class name of complex type in WSDL

node.js - GitLab CI/CD shell 执行器 : npm command not found

php - 在 PHP 7.2 中进行 Curl 安装,但在应用程序中不起作用

php - fatal error : Cannot use string offset as an array

php - 在 'country_id' 子句中获取列 'where' 是不明确的 - cakephp 1.3 中的搜索查询错误

PHP MySQL登录函数

Mysql例程错误

node.js - utility.pump(streamA, stream) 和 stream.pipe(stream) 有什么区别?

node.js - 自主维护可用工作人员状态的最佳方法是什么

javascript - 在 WordPress 的 javascript 中留下 API key 等私有(private)信息是否安全?