jQuery UI源方法
source : function(request, response) { response (/*some data*/)}
我的代码如下
$.fn.foo = function(uri){
return this.each(function(){
var _response;
//get that 'response' using source method
//and assign it (response) to a variable say '_response'
//$.fn.foo.methods.source.call($this[0], uri) can be used if possible to get that
});
}
$.fn.foo.methods {
source: function(uri, response) {
$.get(uri, function(data){
//maybe as
response(data);
});
}
}
请帮帮我,我只是不能导出从$.get(uri, function(data){})
本地变量获得的数据
您需要使用一个同步GET
请求。
$.fn.foo.methods {
source: function(uri, response) {
var result;
$.ajax({
url: uri,
async: false,
success: function(data) {
result = data;
}
});
return result;
}
}
编辑:
如果要使用回调方法,可以按照以下方式进行操作。但是请注意,这现在是异步的。
$.fn.foo = function(uri){
return this.each(function() {
$.fn.foo.methods.source.call($this[0], uri, function (data) {
// Do something with the data asynchronously, once the request has returned
});
});
}
$.fn.foo.methods {
source: function(uri, response) {
$.get(uri, response);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句