How to refresh JQuery mobile table after a row is added dynamically

后端 未结 2 1492
后悔当初
后悔当初 2021-01-19 10:41

I am adding rows to a JQ Mobile table based on a JSON string that I am getting from the server.

The first time I go to the page after a refresh, none of the styling

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-19 11:36

    I would suggest you use .trigger('create'); and refresh the page, jQM Docs:

    • http://jquerymobile.com/demos/1.0.1/docs/pages/page-scripting.html

    Enhancing new markup
    The page plugin dispatches a pagecreate event, which most widgets use to auto-initialize themselves. As long as a widget plugin script is referenced, it will automatically enhance any instances of the widgets it finds on the page.

    However, if you generate new markup client-side or load in content via Ajax and inject it into a page, you can trigger the create event to handle the auto-initialization for all the plugins contained within the new markup. This can be triggered on any element (even the page div itself), saving you the task of manually initializing each plugin (listview button, select, etc.).

    For example, if a block of HTML markup (say a login form) was loaded in through Ajax, trigger the create event to automatically transform all the widgets it contains (inputs and buttons in this case) into the enhanced versions. The code for this scenario would be:

    $( ...new markup that contains widgets... ).appendTo( ".ui-page" ).trigger( "create" );
    

提交回复
热议问题