How to get jQuery mobile magic to work in “pageshow” event handler? (JQM 1.1.0)

爷,独闯天下 提交于 2020-01-15 10:40:33

问题


Hey I'm having a problem with inserting an ICanHaz.js template into a jquery mobile doc on the 'pageshow' event. The HTML inserts into the DOM fine and displays fine, but none of the jQuery Mobile UI classes are applied etc. The following code is coffeescript:

    $('#trailRewards').live 'pageshow', (event, ui) =>
        html = ich.t_reward_list()
        $(html).trigger('create')
        $('#trailRewards').html(html)

Am I calling the 'create' event at the wrong time, or am I triggering the wrong event?

If the html is already in the div and I just use regular jquery selectors to update bits of content it works, but then of course I can't use templates which is annoying!

Cheers :)

EDIT: Fixed typos


回答1:


I ended up finding out the best solution by using the "pagebeforecreate" event instead. See here for more info: http://jquerymobile.com/test/docs/api/events.html

    $('#trailRewards').live 'pagebeforecreate', (event, ui) =>
        html = ich.t_reward_list()
        $(html).trigger('create')
        $('#trailRewards').html(html)

Hope that helps someone who has the same issue as me :)



来源:https://stackoverflow.com/questions/11168889/how-to-get-jquery-mobile-magic-to-work-in-pageshow-event-handler-jqm-1-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!