情况:我有网站,用 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:{一些垃圾,由上面的输入和代码制作}
Mabe我做错了。