问题描述
我有这个重载功能
SN.Reload =函数(设置){
var _timer = null;
var $ grid = null;
var init = function(){
$ grid = $(settings.wrapperSelector);
if(_timer> 0 || _timer!= null)
_timer = settings.timer;
else
_timer = 600000;
window.setInterval(function(){
LoadData();
},_timer);
};
$ b $ var LoadData = function(){
$ .ajax({
url:'/data.json',
类型:'GET' ,
dataType:'json',
cache:false,
成功:UpdateData,
错误:DataErrorHandler
});
};
$ b $ p
$ b 在正常状态下,它将在X分钟运行LoadData函数 -
我现在有另一个命名函数
SN.CreateJsonFromDate = function(settings){
....
var SuccessLoad = function(){
_dateLoader.hide();
_wrapper.slideUp();
$ b}
}
是否可以使用SN.Reload中的LoadData在SN.CreateJsonFromDate中的SuccessLoad函数中?
LoadData函数在成功时调用UpdateData并从json数据更新HTML,我想在SN.CreateJsonFromDate中再次调用此函数,因为这会生成一个新的json文件。
解决方案不,因为 LoadData
SN.Reload
如果您想重新使用 LoadData 函数,不要将它的范围限制在 SN.Reload
中,而是可能(取决于你想要的),将它作为 SN.LoadData
I have run into a problem with a named function in Javascript.
I have this reload function
SN.Reload = function(settings) {
var _timer = null;
var $grid = null;
var init = function () {
$grid = $(settings.wrapperSelector);
if (_timer > 0 || _timer != null)
_timer = settings.timer;
else
_timer = 600000;
window.setInterval(function () {
LoadData();
}, _timer);
};
var LoadData = function () {
$.ajax({
url: '/data.json',
type: 'GET',
dataType: 'json',
cache: false,
success: UpdateData,
error: DataErrorHandler
});
};
}
In the normal state this will run LoadData function at X minutes - this works as intended.
I now have another named function
SN.CreateJsonFromDate = function (settings) {
....
var SuccessLoad = function () {
_dateLoader.hide();
_wrapper.slideUp();
}
}
Is it possible to use LoadData from SN.Reload Inside the SuccessLoad function in SN.CreateJsonFromDate ?
The LoadData function call UpdateData on success an updates the HTML from the json data and I want to call this function again in SN.CreateJsonFromDate as this will generate a new json file.
解决方案 No, because simply LoadData
does not exist outside the scope of SN.Reload
If you do want to re-use the LoadData
function, do not restrict it's scope to being inside SN.Reload
and instead, perhaps (depending on what you want), attach it to the namespace as SN.LoadData
这篇关于在javascript中调用其他命名函数的命名函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!