jQuery Mobile - listview() with data-filter=“true” and ajax content

浪尽此生 提交于 2019-12-13 05:17:57

问题


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?


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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.


来源:https://stackoverflow.com/questions/8306645/jquery-mobile-listview-with-data-filter-true-and-ajax-content

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