0

我想在拖动后访问 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'});

谢谢!

4

1 回答 1

0

有时它很容易

_test: function(){  
    $map = $this.map;

    $map.on('drag',{map: $opts.map}, function(e, dd) {
        // access with event.data
        alert(e.data.map);

    });
},
于 2012-12-02T05:56:21.000 回答