我尝试在函数内部调用另一个方法,但如果我在内部setTimeout
使用,它找不到该方法。我已经尝试了一些解决方案,但似乎没有解决它,所以我在这里问。this.install()
setTimeout
我有的代码,记得看看我尝试做什么的评论:
jQuery(window).load(function () {
$.widget( "testing.updater", {
options: {
},
_create: function() {
//
this.element.addClass('text');
//
this.downloadFiles('bootstrap');
},
downloadFiles: function(packagen) {
var ajax = $.ajax({
type: "POST",
url: "responses/test.php",
data: "download=" + packagen,
success: function(data) {
var obj = jQuery.parseJSON( data);
$('.text').append('Downloading files...<br>');
$('#updateBtn').attr("disabled", true);
if (obj.downloaded) {
setTimeout(function(message){
$('.text').append(obj.message+'<p><p>');
// Down here I want to call another method
// like this.install(); <.. but ain't working..
}, 5000);
} else {
return $('.text').append('<p><p> <font color="red">'+obj.message+'</font>');
}
}
});
},
install: function() {
// I want to run this method inside
// prev method, look above comment
},
});
$('#updateBtn').on('click',function(){
var test = $('.updater').updater();
test.updater();
});
});