2013-10-01 56 views
0

在初始化或刷新我的ul时出现问题 - 我在我的代码示例中使用的方法在我正在使用的另一个函数中工作,但不在此处......我必须缺少某些东西?jQuery Mobile Listview不刷新

$(data).find("#HospitalDescriptions").find('th').filter(function(){ 
    if (this.innerHTML !== '') { 
    var bgcolor = $(this).css("background-color"); 
    var txtcolor = $(this).css("color"); 
     if (bgcolor !== ''){ 
      $('#information').append('<div id="alertColors"><ul><li><span style="background-color:' + bgcolor + ';color:' + txtcolor + ';">' + this.innerHTML + '</span></li></ul></div>'); 
     } else { 
      $('#information').append('<li>' + this.innerHTML + '</li>'); 
     } 
    } 
    $('#information').listview('refresh'); // not working! 
}); 

,这里是我的HTML UL是在代码中创建:#ID的

<div data-role="page" data-theme="b" id="hospitals" data-add-back-btn="true"> 
    <div data-role="header"> 
     <h1>HOSP-HEADER</h1> 
     <a class="ui-btn-right" id="infoButton" onclick="$('#locations').listview('refresh');">Refresh</a> 
    </div><!-- /header --> 

    <div data-role="content" data-theme="b" id="regions"> 

     <div data-role="content"> 
      <h4>Information</h4> 
      <ul data-role="listview" data-inset="true" id="information"> 
       <!-- AJAX CONTENT --> 
      </ul> 
     </div> 

     <div data-role="collapsible"> 
      <h4>Regions I, II, III</h4> 
      <ul data-role="listview" data-inset="true" id="region3"> 
       <!-- AJAX CONTENT --> 
      </ul> 
     </div> 

     <div data-role="collapsible"> 
      <h4>Region IV</h4> 
      <ul data-role="listview" data-inset="true" id="region4"> 
       <!-- AJAX CONTENT --> 
      </ul> 
     </div> 

     <div data-role="collapsible"> 
      <h4>Region V</h4> 
      <ul data-role="listview" data-inset="true" id="region5"> 
       <!-- AJAX CONTENT --> 
      </ul> 
     </div> 

    </div> 
+0

严正,不.innerHTML返回一个DOM对象?如果是这样,那么难怪if查询大部分都会失败。 – reporter

+0

如果查询不失败,结果是好的,它只是没有在jQuery Mobile中格式化并显示为标准li – BarclayVision

+1

您应该使用'.each'而不是'.filter'来确保您的易读性和稳定性码。 '。 – Rodik

回答

0

失去了联系。 #信息是一个非创造性的div而非div。删除嵌套div里面的ul:

$(data).find("#HospitalDescriptions").find('th').filter(function(){ 
    if (this.innerHTML !== '') { 
    var bgcolor = $(this).css("background-color"); 
    var txtcolor = $(this).css("color"); 
     if (bgcolor !== ''){ 
      $('#information').append('<li><span style="background-color:' + bgcolor + ';color:' + txtcolor + ';">' + this.innerHTML + '</span></li>'); 
     } else { 
      $('#information').append('<li>' + this.innerHTML + '</li>'); 
     } 
    } 
    $('#information').listview('refresh'); 
});