SetHTML 之后立即在 FCKeditor 上 ResetIsDirty -- Javascript 的并发/计时问题
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我仍然对直接答案感兴趣,但我倾向于认为这不太可行。它需要某种睡眠函数,但 JavaScript 并没有进入这个领域。
但是,您应该要做的是处理FCKeditor_OnComplete事件:
该事件被放置在带有延迟设置的脚本标记
中。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:
This was placed in a script tag
with defer set.我知道,这个问题不是实际的,但它可能对某人有用。尝试使用:
I know, the question is not actual, but it may be useful to someone. Try to use: