How to remove elements from listview JQUERY mobile

那年仲夏 提交于 2019-12-12 10:43:25

问题


There is a list view and this is loaded dynamically upon loading the page. This adds elements inside list view. The problem is i have placed backbutton.After going to previous screen and returning back to current screen it is loading the data and appending to the List View.

I need to remove the <li> elements from the list view.

The HTML code snippet.
<ul id="mymenu" data-role="listview" >
</ul>

Jquery Code Snippet.
$("#mypmenu").append('<li><a href='+ "#" + ' id="a"  "> <img src="letterheader.png" >'+ this.textContent + '  </a> </li>'); 


Now i need to remove the elements from the list view (mymenu)which are loaded already.

回答1:


Try emptying your list before appending list items first. Afterwards, make sure to call the refresh function of the listview widget, so jQuery Mobile will be rendering your list correctly.

$("#mypmenu").empty().append('<li><a href='+ "#" + ' id="a"  "> <img src="letterheader.png" >'+ this.textContent + '  </a> </li>').listview("refresh"); 

See also http://forum.jquery.com/topic/dynamically-generated-listview




回答2:


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

does the job for me




回答3:


this work for me

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



回答4:


Don't use append then.
use

$("#mypmenu").html('<li><a href='+ "#" + ' id="a"  "> <img src="letterheader.png" >'+ this.textContent + '  </a> </li>').listview("refresh");


来源:https://stackoverflow.com/questions/8727272/how-to-remove-elements-from-listview-jquery-mobile

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