JavaScript :- 在初始化之前不能在 A 上调用方法;尝试调用方法 'resizeGrid'



嗯,我想调用一个函数,对象&方法:

File 1 --
var a ={
resizeGrid : function(){
//this manipulates the height & width of a grid
}
}
File 2 --
var b ={
manipulateGrid: function(){
$('#containerGrid_0').a('resizeGrid');
}
}

我正在尝试将旧版本的Jquery转换为最新版本。1.7到2.2.2使用迁移插件。面对这个问题" cannot call methods on A prior to initialization; attempted to call method 'resizeGrid'"

尝试了下面的一些解决方案,但没有工作。$('#containerGrid_0').a().a('resizeGrid');

看的信息jquery ui Dialog:在初始化之前不能调用Dialog的方法

根据您提供的内容,我无法确切地说出您的函数在做什么,或者您如何使用它们。但是这里有一个如何初始化它们的例子。

你可以通过点击来使用它jsFiddle示例

$.fn.A = function(sFunc){
var agrid = {
resizegrid:function(ele){
ele.append('<div>Hello</div>')
}
}
agrid[sFunc](this)
};
$.fn.B = function(sFunc){
var help = {
checkResize:function(ele){
ele.A('resizegrid')
}
}
help[sFunc](this)
}
$('#btn').click(function(){
$('body').B('checkResize')
})

最新更新