我想在拖动后访问 vars,但是当我多次初始化小部件时,$this 和 $opts 将被覆盖并且始终为“y”。如何存储和访问正确的变量?
$.widget("custom.test", {
options: {
map: ''
},
_create: function(){
$this = this;
$opts = $this.options;
if($opts.map){
$this._createmap();
$this._loadmap();
}
$this._test();
},
_test: function(){
$map = $this.map;
$map.drag(function(e, dd) {
// how to get the correct option here
// $opts.map is to global?
});
},
_createmap: function(){
$this.map = $('<div></div>').addClass('map');
},
});
$(x).test({map: 'x'});
$(y).test({map: 'y'});
谢谢!