2014-03-12 202 views
0

如何崩溃嵌套可压缩集所有嵌套可折叠的设置和可折叠的元素在jQuery Mobile的?如何折叠嵌套可折叠集中的所有嵌套可折叠集和可折叠元素?

下面是在的jsfiddle代码: http://jsfiddle.net/ycP8y/

<body> 
<div data-role="content"> 
    <div data-role="collapsible-set"> 
     <div data-role="collapsible"> 
      <h1> 
       <div class="ui-btn-up-c ui-btn-corner-all custom-count-pos">47</div> 
       Test</h1> 

      <div data-role="collapsible-set"> 
       <div data-role="collapsible"> 
        <h1> 
         <div class="ui-btn-up-c ui-btn-corner-all custom-count-pos">47</div> 
         Test</h1> 

        <div data-role="collapsible-set"> 
         <div data-role="collapsible"> 
          <h1> 
           <div class="ui-btn-up-c ui-btn-corner-all custom-count-pos">47</div> 
           Test</h1> 

         </div> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

回答

0

假设你正在使用JQM 1.2在你的小提琴,你可以调用触发( “崩溃”)上的所有collapsibles( http://demos.jquerymobile.com/1.2.1/docs/content/content-collapsible-methods.html):

$(document).on("pageinit", function(){ 
    $("#btnCollapse").on("click", function(){ 
     $("[data-role=collapsible]").trigger("collapse"); 
    }); 
}); 

更新FIDDLE

+0

感谢您的信息。如果我需要在可折叠的点击中调用此功能,而不是在其他按钮上。我更新了小提琴,为您提供更多的界面。 –

+0

你想折叠所有子collapsibles当父被折叠以便下次您展开有没有孩子展开的时间?如果是这样,使用可折叠的小部件的崩溃事件(http://demos.jquerymobile.com/1.2.1/docs/content/content-collapsible-events.html),然后触发所有的孩子崩溃collapsibles:$(此).find( '[数据角色=可折叠]')。触发器( “崩溃”) – ezanker