2016-09-28 134 views
1

我目前正在通过模块化模式处理应用程序。ajax完成后重新绑定

我现在正在得到的问题是,一旦Ajax完成,我想能够在对象内激发一个函数。我可以看到的对象,但是当我指定一个函数时,它会失败并返回为未定义

JS

var TestCase = { 
    settings: { 
    cu: $('.select'), 
    }, 

    init: function() { 
    se = this.settings; 
    }, 

    windowsReady: function() { 
    TestCase.init(); 
    if ($.fn.selectBox) { 
     TestCase.selectBind(); 
    } 
    }, 

    ajaxComp: function() { 
    TestCase.init(); 
    TestCase.selectBind(); 
    }, 

    selectBind: function(){ 
    se.cu.selectBox(); 
    }, 

}; 

JS火 - 当其通过准备调用加载的selectBind工作正常。然而,正如前面提到的,ajaxcomplete会一直保持为未定义的TestCase.ajaxComp();或直接调用TestCase.selectBind();请注意,当我console.log(TestCase)它列出所有的对象。在$(document).ajaxSuccess(...)方法将是jQuery的对象,而不是测试用例对象的范围

se = this.settings; 

this

$(document).ready(function() { 
    TestCase.windowsReady(); 
}); 

$(document).ajaxSuccess(function() { 
    console.log(TestCase); 
    TestCase.ajaxComp(); 
    console.log('completed'); 
}); 
+0

为什么不只是把线路中的$(文件)。就绪6-8()调用? –

+0

你是什么意思“回到未定义”?您可能希望包含您收到的整个错误消息。 –

+0

@MikeMcCaughan那是我得到的唯一的错误。根据我的描述,我试图调用'TestCase.ajaxComp()' - 它带着'undefined'返回。当我调用'TestCase'时,它列出了存储在'TestCase'内的所有对象。 –

回答

0

这是因为该行的happenning。

尝试将其更改为se = TestCase.settings;

+0

似乎没有与您的建议工作。 –