【问题标题】:jQuery Mobile nested list refresh solutionjQuery Mobile 嵌套列表刷新解决方案
【发布时间】:2012-05-27 18:40:27
【问题描述】:

我正在尝试使用 jquery Mobile 1.1 版刷新嵌套列表的解决方法,该版本目前给您留下一个空白页面。

我知道一个现有的解决方案是启用 pushState,但这会将您送回列表的根目录,并在您的下一个嵌套列表视图中使用历史状态。

我在下面提出的解决方案并不漂亮,但适用于 iOS 和更新的 android。

$(document).bind("mobileinit", function(){

 var urlEx = '#&ui-page=5-0';  //ending of nested list url

 if (window.location.href.indexOf(urlEx) != -1){

  history.replaceState("", "0", "index.php");
   setTimeout("window.location.href='https://FULLURL#/FULLURL&ui-page=5-0'",100);
 }

 window.history.pushState("", "0", "index.php"); 

});

我意识到并不是每个浏览器都支持 pushState 和 replaceState,我可以尝试使用:

window.location.href = window.location.href.substring(0,window.location.href.indexOf('#'));

相反,但它会变得更加不稳定。

我希望有人能阐明哪些方面可以做得更好,或者如何做得更好/更可靠。

【问题讨论】:

  • 如果您担心可靠性,为什么不使用稳定版本的 JQM?
  • 我的错误。我 ment 1.1 超越自己:)
  • 能否提供 HTML 代码,以便我们寻找可能的解决方法?
  • 我感觉你做的太多了,可以在不触及状态的情况下修复它,但我不确定我是否理解你的情况。到(不)工作代码的链接将是最好的。或者在某处张贴一个拉链
  • 如果要将子元素添加到列表视图,则可以在对象上调用 .refresh('listview')。见:stackoverflow.com/questions/7083507/…

标签: javascript jquery jquery-mobile browser-history pushstate


【解决方案1】:

$("#<mySelector>").listview("refresh");

$("#<mySelector>").refresh("listview");

除非我完全误解了您的问题,否则您应该能够使用上述任何一行来刷新您要添加到的列表,其中 <mySelector> 是任何与 JQuery 兼容的选择器,它将返回您的列表视图.

【讨论】:

    【解决方案2】:

    这段代码对我有用:

    $("#newList").append("<li class='ui-li-desc'><div><b>"+data[i].Title+":</b></div><small><div class='ui- li-desc'>"+data[i].Content+"</div></small></li>");
    
    $("#newList").listview("refresh");
    

    这里#newlist是ul的ID,data是一个对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多