问题
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