简体   繁体   English

jquery-mobile事件顺序,为什么setTimeout将$ this设置为undefined?

[英]jquery-mobile event order and why does setTimeout set $this to undefined?

I need to delay the execution of the 2nd function crumble() after stackUp() has run. stackUp()运行后,我需要延迟第二个函数crumble()的执行。

I have tried setting an event-order with pagechange vs. pagebeforeshow like this: 我曾尝试与pagechange对这样pagebeforeshow设置的事件顺序:

$('div:jqmData(role="page")').bind( "pagechange", function( event, data) {
   stackUp(event, data);
});

$('div:jqmData(role="page")').live('pagebeforeshow', function(event, data){
     crumble(event, data, $(this) );
});

Doesn't work and setTimeout like this: 像这样不起作用和setTimeout

$('div:jqmData(role="page")').live('pagebeforeshow', function(event, data){
     window.setTimeout(function (event, data, $(this)) {
       crumble(event, data, $(this) );
     },500);
});

makes $(this) undefined , so this also doesn't help either. 使$(this) 未定义 ,因此这也无济于事。

Question : 问题
How can I make sure crumble fires when stackup is done? 完成堆叠后,如何确保崩溃
Is $(this) becoming undefined, because it's window.setTimeout() (and not $(this).setTimeout)? $(this)是否因为它是window.setTimeout()(而不是$(this).setTimeout)而变得不确定?
What's the correct event-order in jquery-mobile? jQuery-mobile中正确的事件顺序是什么?

Big THANKS! 太谢谢了! for help. 求助。

Your setTimeout function makes no sense. 您的setTimeout函数没有任何意义。 That's not even valid syntax - $(this) can't be a function parameter name! 那甚至不是有效的语法- $(this)不能是函数参数名称!

What you're looking for is: 您正在寻找的是:

$('div:jqmData(role="page")').live('pagebeforeshow', function(event, data) {
    var $this = $(this);
    window.setTimeout(function() {
        crumble(event, data, $this);
    }, 500);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM