我有JQuery UI小部件附加了DOM元素来完成这项工作。这个小部件在_destroy方法中删除了这个元素,所以它会自行清理。如何替换具有自定义元素的JQuery UI小部件
一切都很好,直到我尝试用一些其他小部件替换小部件。原始小部件被删除(销毁方法将删除小部件自定义元素),但新的小部件不附加。
最好的说明是代码,所以这里是例子:http://jsfiddle.net/71xdxLvp/3/
的问题是:如何更换部件我?
注:
我知道问题出在哪里,但我不知道如何解决它。
问题是在方法replaceWith
的jquery.js - 看到代码中的注释:
return this.each(function() {
var next = this.nextSibling, // nextSibling is widgets custom element
parent = this.parentNode;
// Widget is removed and the widgets custom element is removed too
jQuery(this).remove();
if (next) {
// New widget should be prepended to the widgets custom element, but
// the element is already removed from DOM.
// Method before() check this and won't append new widget
jQuery(next).before(value);
} else {
jQuery(parent).append(value);
}
});
编辑:
replaceWith
由第三方框架称为Apache Wicket
部件它创建DOM元素是CodeMirror
不幸的是'.replaceWith'被第三方库(Wicket)调用,所以我不能自己模拟它。 :( – 2015-04-02 14:02:37
我看到了;检查编辑是否有帮助,我通常会推荐阅读你的小部件的结构,因为replaceWith可能不是依赖兄弟的唯一函数 – blgt 2015-04-02 14:30:03
感谢您的更新 - 这是一个混乱的方式,但我认为它可以工作,Widget也是第三方(见我的编辑),所以我不能轻易修改它的结构。 – 2015-04-08 08:30:42