你可以添加一個全局超時功能,每一秒鐘左右(時間間隔由你)檢查:
function updateCardIfDirty() {
if (tinyMCE.isDirty()) {
// rerender the card
}
}
setInterval(updateCardIfDirty, 2000); // check every 2 seconds.
一個清潔的解決辦法可能是檢查每一個他們使TinyMCE的編輯器發生變化時, 。這可以通過onChange()
事件tinyMCE provides成爲可能,如下所示:
tinyMCE.init({
...
setup : function(ed) {
ed.onChange.add(function(ed, l) {
// rerender the card
});
}
});
第一種方法的缺點是,它會執行每2秒,即使他們不編輯卡了一個小時。第二種方法的缺點是,如果他們在1秒內執行10次編輯,那麼在該秒鐘內將卡片放回10次。
所以最後,讓我們嘗試第三種方法,其得到兩全其美,並失去我們提到的這兩個缺點:
tinyMCE.init({
...
setup : function(ed) {
ed.onChange.add(function(ed, l) {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(function(){ timeout=null; rerenderCard(); }, 1000);
});
}
});
使用「isdirty」的方法我無法得到它的工作時,和按變化不更新就夠了(你需要點擊關閉編輯器或按Enter鍵得到它的更新。 – 2011-01-21 13:02:06