情境:我有网站,用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:{一些垃圾,由输入和上面的代码}
我这样做是不对的。
发布于 2015-09-04 14:16:21
下面是我在源代码中找到的无文档函数:
doc.attach_ace(editor, true);第二个变量是保留编辑器内容,这样就可以在编辑器中设置自己的文本。
希望这是有用的。
https://stackoverflow.com/questions/32354126
复制相似问题