SetHTML 之后立即在 FCKeditor 上 ResetIsDirty -- Javascript 的并发/计时问题

发布于 2024-09-27 20:24:50 字数 503 浏览 0 评论 0原文

我正在使用 IsDirty 来检查 FCKeditor 中的更改。不幸的是,它的功能似乎是异步的。

这是失败的代码:

var txtObj = $('activities').EstActText1.id;
var oEditor = FCKeditorAPI.GetInstance(txtObj);
oEditor.SetHTML(jsonObj.DATA.ESTACTTEXT1.toString());
oEditor.ResetIsDirty();

问题是,SetHTML 不会立即生效(如果您随后使用 GetHTML 进行检查,它将返回文本区域中之前的内容)。因此,ResetIsDirty 将运行,然后 HTML 将实际更改,并且脏标志将再次设置。

有什么方法可以在继续之前强制 SetHTML 调用完成吗?如果没有,是否有任何方法(除了会增加延迟且不一定总是有效的 ghetto setTimeout 调用之外)来确保 ResetIsDirty 在 HTML 更改后真正生效?

I am using IsDirty to check for changes in my FCKeditor. Unfortunately, it seems that its functions are asynchronous.

Here is the failing code:

var txtObj = $('activities').EstActText1.id;
var oEditor = FCKeditorAPI.GetInstance(txtObj);
oEditor.SetHTML(jsonObj.DATA.ESTACTTEXT1.toString());
oEditor.ResetIsDirty();

The problem is, SetHTML does not take effect immediately (if you put a check right afterward using GetHTML, it will return what was previously in the textarea). Thus, ResetIsDirty will run, THEN the HTML will actually be changed, and the dirty flag will be set again.

Is there any way I can force the SetHTML call to complete before continuing? If not, is there any way (besides a ghetto setTimeout call that will add latency and not necessarily always work) to make sure that the ResetIsDirty will actually take effect after the HTML is changed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光瘦了 2024-10-04 20:24:50

我仍然对直接答案感兴趣,但我倾向于认为这不太可行。它需要某种睡眠函数,但 JavaScript 并没有进入这个领域。

但是,您应该要做的是处理FCKeditor_OnComplete事件:

function FCKeditor_OnComplete( editorInstance )
{
    editorInstance.Events.AttachEvent( 'OnAfterSetHTML', function(){
        editorInstance.ResetIsDirty(); // clean flag to avoid having to save
    } ) ;
    editorInstance.ResetIsDirty(); //clean flag upon initial load as well
}

该事件被放置在带有延迟设置的脚本标记中。

I still would be interested in a direct answer, but I'm leaning on the side of that not being very feasible. It would require something of a sleep function, but JavaScript doesn't go toward that realm.

However, what you're supposed to do is handle the FCKeditor_OnComplete event:

function FCKeditor_OnComplete( editorInstance )
{
    editorInstance.Events.AttachEvent( 'OnAfterSetHTML', function(){
        editorInstance.ResetIsDirty(); // clean flag to avoid having to save
    } ) ;
    editorInstance.ResetIsDirty(); //clean flag upon initial load as well
}

This was placed in a script tag with defer set.

装纯掩盖桑 2024-10-04 20:24:50

我知道,这个问题不是实际的,但它可能对某人有用。尝试使用:

ckeditor = CKEDITOR.instances['Editor_ID'];
ckeditor.setData(lyr_data.lyrics,function(){
    ckeditor.updateElement();
    ckeditor.resetDirty();
});

I know, the question is not actual, but it may be useful to someone. Try to use:

ckeditor = CKEDITOR.instances['Editor_ID'];
ckeditor.setData(lyr_data.lyrics,function(){
    ckeditor.updateElement();
    ckeditor.resetDirty();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文