ウィジェットファクトリを使用してjQueryウィジェットを開発してきました。
同じページ上の複数のDOM要素でウィジェットをインスタンス化すると、オプションオブジェクトを除いて、ウィジェット内のすべてのオブジェクトがDOM要素間で共有されることに気付いた以外はすべて問題ありません。
すべてのオブジェクトと関数には、ウィジェット内に独自のインスタンスがあると思いました。私は明らかに何かが欠けているので、いくつかのガイダンスをいただければ幸いです。
例えば:
(function($) {
$.widget("a07.BearCal", {
options: { className : "test" },
_glbl: { something: "" },
_create: function() {
this._glbl.something = this.element.attr('class');
this.options.className = this.element.attr('class');
},
});
})(jQuery);
// Instantiate widget on .full
$('.full').BearCal();
//Should output full
console.log($('.full').data('BearCal')._glbl.something);
//Should output full
console.log($('.full').data('BearCal').options.className);
// Instantiate widget on .mini
$('.mini').BearCal();
//Should output mini
console.log($('.mini').data('BearCal')._glbl.something);
//Should output mini
console.log($('.mini').data('BearCal').options.className);
//Should output full but outputs mini
console.log($('.full').data('BearCal')._glbl.something);
//Should output full
console.log($('.full').data('BearCal').options.className);
この実例:http://jsfiddle.net/NrKVP/4/
前もって感謝します!