jquery ui で奇妙な動作に遭遇しました (jquery 1.8.3、jquery-ui 1.9.2 でテスト済み)。
親と子のウィジェットがあり、親の _create メソッドで、新しく作成された子に親の自己参照を与えます。子内からこの参照にアクセスしようとすると、子の構築後に宣言されたすべての関数とプロパティが利用できません。
(function ($) {
$.widget("ui.parentWidget", $.ui.mouse, {
version: "@VERSION", widgetEventPrefix: "parentWidget",
_create: function () {
var self = this;
self.child = $("<div/>")
.childWidget({ parent: self })
.appendTo(self.element);
self.parentName = "parent";
},
parentFeature: function() {
return "feature";
},
getChild: function() {
return this.child;
},
updateChild: function () {
var self = this;
self.child.childWidget("update", self);
}
});}(jQuery));
子ウィジェット
(function ($) {
$.widget("ui.childWidget", $.ui.mouse, {
version: "@VERSION", widgetEventPrefix: "childWidget",
options: {
},
_create: function () {
},
childParent: function () {
return this.options.parent;
},
updatedParent: function() {
return this.newParent;
},
update: function(parent) {
var self = this;
self.newParent = parent;
}
});
}(jQuery));
出力をテストするために、親を作成し、その子を取得し、子から子の親を読み取り、結果を表示します。
var parent = $("<div/>").parentWidget();
parent.parentWidget("updateChild");
var child = parent.parentWidget("getChild");
var childParent = child.childWidget("childParent");
var updatedParent = child.childWidget("updatedParent");
childParent.parentName
またはchildParent.parentFeature()
ie7undefined
とie8にあり、他のすべての場所で正常に動作updatedParent
し、そのすべてのコンテンツを所有しています。
私の質問は、これはバグですか?または、jquery ui プラグインを適切に使用する方法を誤解しましたか。