0

This is my html:

<ul data-role="list-view" data-filter="true"></ul>

My JS loads the ul with data and then I call listview().

$('#page').live('pagebeforecreate', function(){
        // My Ajax code
    });
    $('#page').live("pageinit", function(){
        $('#page ul').listview();
    });

That works except the search bar at the top doesn't appear. What am I missing?

4 Answers 4

4

You have

data-role="list-view"

When the right way is

data-role="listview"

that is why the search bar at the top doesn't appear.

Sign up to request clarification or add additional context in comments.

Comments

0

I think you need to use $('#page ul').listview('refresh'); instead of just $('#page ul').listview();. You need to refresh a jQuery-Mobile component when you update it via Ajax.

2 Comments

If I do that, then I get this error in firebug: uncaught exception: cannot call methods on listview prior to initialization; attempted to call method 'refresh'
You wrote data-role="list-view" instead of data-role="listview". May it have something to do with it?
0

You'd have to call:

$('#page ul').listview('create');

after you are done populating your list with jscript.

To refresh it's content (only after it's creation), you could call:

$('#page ul').listview('refresh');

see jqm documentation

Comments

0

Instead of calling $('#page').live("pageinit", function(){ $('#page ul').listview(); });

Do the following:

  $('#page').live("pageinit", function(){
    init();
    });


<ul id="mylist" data-role="listview" data-theme="b" data-filter="true" >

</ul>

function init()
{
    type: "GET",
   $.ajax({
     url: "BirthdayInvitations.xml",
    dataType: "xml",
    success: function ParseXml(xml)
    {
         $(xml).find("event").each(function() {  
     $("#mylist").append('<li><a href="' + "#" + '">' +this.textContent + '</a></li>');
     }); 
     $("#mylist").listview('refresh');   
     }}); 

   }

This is working i tried it out and i am using in my application.

1 Comment

This did not work for me. I got this error in firebug: uncaught exception: cannot call methods on listview prior to initialization; attempted to call method 'refresh'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.