[英]jQuery Mobile dynamically remove data-theme then refresh <ul>
I am implementing a “have not yet viewed” list where the user sees a list of items in a ul and those the user has not viewed have a data theme applied to highlight them. 我正在实现一个“尚未查看”列表,其中用户看到ul中的项目列表,而那些用户尚未查看的项目则应用了数据主题来突出显示它们。 When the user clicks on the item it is displayed, and I need to remove the data theme so the item is no longer highlighted. 当用户单击该项目时,将显示该项目,并且我需要删除数据主题,以便该项目不再突出显示。
I have the logic correct to actually remove the attribute as I can see in the Elements section of Chrome's Developer Tools the attribute is no longer in the li. 我有正确的逻辑来删除属性,正如我在Chrome开发人员工具的“元素”部分所看到的那样,该属性不再存在。 But the highlight is still visible in the rendered page. 但是突出显示的部分仍在渲染页面中可见。
I've searched and have seen a number of suggestions involving refreshing the page, list, etc., all to no avail. 我进行了搜索,并发现了一些涉及刷新页面,列表等的建议,但都无济于事。 You can see some of the attempts as follows (in the function "this" is the li): 您可以看到一些尝试,如下所示(在函数“ this”中是li):
$(this).removeAttr("data-theme");
//$(this).closest("ul").listview("refresh");
//$(this).closest("ul").listview();
//$('#mylist').listview();
//$("#content-notifications").page();
//$("#content-notifications").page("destroy").page();
//if ( $("#content-notifications").data("page") ) {
// $(this).closest("ul").listview("refresh");
//};
Anyone have the correct solution, because I can't find it! 任何人都有正确的解决方案,因为我找不到它!
Thanks- 谢谢-
Matt 马特
You have to manually remove the class for the old theme in li and add the class for new theme. 您必须手动删除li中旧主题的类并添加新主题的类。
$(document).on("click","li",function(){
$(this).attr("data-theme","b").removeClass("ui-btn-up-a").addClass("ui-btn-up-b")
});
Demo here - http://jsfiddle.net/ENYxw/ 此处演示-http: //jsfiddle.net/ENYxw/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.