Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery mobile -> .append() removes CSS?

when appending items to my list, the complete style of jquery mobile is gone... dont know how to fix this?

This is currently working: when not appending the list-items, all styles are fine.

<div class="ui-grid-a">
                <div class="ui-block-a" id="blockaid">
                    <ul id="leftnav" data-role="listview" data-theme="g" data-filter="true" >

                        <li><a href="index.html">
                                <img src="images/bb.jpg" />
                                <h3>Firstname Lastname</h3>
                                <p>123456789</p>
                            </a></li>
                    </ul>

                </div>

               <div class="ui-block-b">
                ...

But if I start using to read the data from else where, all styles are gone:

        $(document).ready(function() {

            $.ajax({
                url: 'test.xml', 
                dataType: "xml",
                success : parse,
                error : function (xhr, ajaxOptions, thrownError){  
                    alert(xhr.status);          
                    alert(thrownError);
                } 


            });

            function parse(document){
                $(document).find("Details").each(function(){


                    $("#leftnav").append(


                    '<li>' + '<a href="#">' + '<img src="images/album-xx.jpg" />' +
                        '<h3>' + $(this).find('Name').text() + '</h3>' +
                        '<p>' + $(this).find('Number').text() + '</p>' +
                        '</a>' + '</li>'
                );
                });
            }
        });

Whats wrong?

Thanks!

like image 892
dotchuZ Avatar asked Aug 29 '11 06:08

dotchuZ


1 Answers

Well, to trigger the automatic style on new elements, using .trigger("create") should do the job.

see : Is it possible to create element on the fly with jQuery Mobile?

or http://jquerymobile.com/demos/1.0b2/#/demos/1.0b2/docs/pages/page-scripting.html

EDIT: $('#leftnav').listview('refresh') is the thing your looking for rather than create.

see: http://api.jquerymobile.com/listview/#method-refresh

like image 145
Py. Avatar answered Oct 21 '22 01:10

Py.