如何从listview JQUERY mobile中删除元素 [英] How to remove elements from listview JQUERY mobile

查看:63
本文介绍了如何从listview JQUERY mobile中删除元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.


推荐答案

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

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"); 

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

这篇关于如何从listview JQUERY mobile中删除元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆