0

I need to inject some extra data into $.getScript call, so it'll be availabe in ready handler, how do I do that?

// since it's called in a loop I need pass context into read handler
$.getScript(path, function (e2) {

};

in regular event handlers I can do do by passing the data as a second parameter and get it by e.data.* from within the event handler:

element.on("event", { extra: "data" }, function(e) { console.log(e.data.extra); });

which doesn't seem to work with $.getScript.

4

1 に答える 1

1

.getSCript()はその機能を提供しませんが、ここでクロージャーを利用できると思います

元:

for(var i = 0; i < x; i++){
    (function(idx){
        $.getScript(path, function (e2) {
            console.log(idx);
        });
    })(i);
}
于 2013-07-18T09:15:19.440 に答える