如何从listview JQUERY mobile中删除元素

有一个列表视图,这是在加载页面时动态加载的。 这会在列表视图中添加元素。 问题是我放置了后退按钮。在转到上一个屏幕并返回当前屏幕后,它正在加载数据并附加到列表视图。

I need to remove the 
  • elements from the list view. The HTML code snippet.
    Jquery Code Snippet. $("#mypmenu").append('
  • '+ this.textContent + '
  • '); Now i need to remove the elements from the list view (mymenu)which are loaded already.

    在首先附加列表项之前尝试清空列表。 之后,请务必调用listview小部件的刷新function,以便jQuery Mobile正确呈现列表。

     $("#mypmenu").empty().append('
  • '+ this.textContent + '
  • ').listview("refresh");

    另见http://forum.jquery.com/topic/dynamically-generated-listview

    $("mypmenu").empty(), followed by $("mypmenu").append()

    为我做的工作

    这项工作对我而言

     $("mypmenu li").remove(); 

    那时不要使用追加。
    使用

     $("#mypmenu").html('
  • '+ this.textContent + '
  • ').listview("refresh");