给定多个国家作为可折叠物品(不在一个集合中),并且每个国家/地区都包含一个带有多个可折叠物品的可折叠集合。标记如下所示:
<div data-role="content">
<div data-role="collapsible" data-iconpos="left" data-collapsed-icon="carat-d" data-expanded-icon="carat-u" class="col" >
<h3 ><div>Country 1</div></h3>
<div data-role="collapsible-set" data-iconpos="left" data-collapsed-icon="carat-d" data-expanded-icon="carat-u" class="governorates">
<div data-role="collapsible" >
<h3 class="Mycollapsible"><div style="color:white;font-weight:normal;">Governorate1</div></h3>
<ul data-role="listview">
<li data-icon='false'> <font class="NameStyle">Village1</font></li>
<li data-icon='false'> <font class="NameStyle"> Village2</font></li>
<li data-icon='false'> <font class="NameStyle"> Village3</font></li>
<li data-icon='false'> <font class="NameStyle"> Village4</font></li>
<li data-icon='false'> <font class="NameStyle"> Village5</font></li>
</ul>
</div>
<div data-role="collapsible">
<h3 class="Mycollapsible"><div style="color:white;font-weight:normal;" >Governorate2</div></h3>
<ul data-role="listview">
<li data-icon='false'> <font class="NameStyle">Village1</font> </li>
<li data-icon='false'> <font class="NameStyle"> Village2</font></li>
<li data-icon='false'> <font class="NameStyle"> Village3</font></li>
<li data-icon='false'> <font class="NameStyle"> Village4</font></li>
<li data-icon='false'> <font class="NameStyle"> Village5</font></li>
</ul>
</div>
</div>
</div>
<div data-role="collapsible" data-iconpos="left" data-collapsed-icon="carat-d" data-expanded-icon="carat-u" class="col" >
<h3 ><div>Country 2</div></h3>
<div data-role="collapsible-set" data-iconpos="left" data-collapsed-icon="carat-d" data-expanded-icon="carat-u" class="governorates">
<div data-role="collapsible" >
<h3 class="Mycollapsible"><div style="color:white;font-weight:normal;">Governorate1</div></h3>
<ul data-role="listview">
<li data-icon='false'> <font class="NameStyle">Village1</font></li>
<li data-icon='false'> <font class="NameStyle"> Village2</font></li>
<li data-icon='false'> <font class="NameStyle"> Village3</font></li>
<li data-icon='false'> <font class="NameStyle"> Village4</font></li>
<li data-icon='false'> <font class="NameStyle"> Village5</font></li>
</ul>
</div>
<div data-role="collapsible">
<h3 class="Mycollapsible"><div style="color:white;font-weight:normal;" >Governorate2</div></h3>
<ul data-role="listview">
<li data-icon='false'> <font class="NameStyle">Village1</font> </li>
<li data-icon='false'> <font class="NameStyle"> Village2</font></li>
<li data-icon='false'> <font class="NameStyle"> Village3</font></li>
<li data-icon='false'> <font class="NameStyle"> Village4</font></li>
<li data-icon='false'> <font class="NameStyle"> Village5</font></li>
</ul>
</div>
</div>
</div>
</div>
.governorates
在javascript中,我通过向可折叠集添加一个类来处理国家/地区扩展/折叠与二级可折叠集
$(document).on('pagecreate', function () {
$(".governorates .ui-collapsible-heading-toggle").on("click", function (e) {
var current = $(this).closest(".ui-collapsible");
if (current.hasClass("ui-collapsible-collapsed")) {
$(".ui-collapsible-content", current).slideDown("fast", function () {
current.trigger("collapsibleexpand");
//hide previously expanded
$(".governorates .ui-collapsible-content-collapsed").slideUp('fast');
});
} else {
$(".ui-collapsible-content", current).slideUp("fast", function () {
current.trigger("collapsiblecollapse");
});
}
});
$(".col .ui-collapsible-heading-toggle").not(".governorates .ui-collapsible-heading-toggle").on("click", function (e) {
var current = $(this).closest(".ui-collapsible");
if (current.hasClass("ui-collapsible-collapsed")) {
$(".ui-collapsible-content", current).not(".governorates .ui-collapsible-content").slideDown("fast", function () {
current.trigger("collapsibleexpand");
});
} else {
$(".ui-collapsible-content", current).not(".governorates .ui-collapsible-content").slideUp("fast", function () {
current.trigger("collapsiblecollapse");
});
}
});
});
这是一个工作演示(基于 Omar 在 OP 评论线程中的初始工作)。