2011-11-29 137 views
0

如何根據Titlesome id擴展或摺疊特定JPanels展開/摺疊特定jpanels

到目前爲止,我可以切換使用按鈕展開/摺疊JPanels。

//Assigning a click event on button to trigger expand/collapse JPanel 
$('#triggerPanelBtn').click(function(){ 
    //alert($('.class').children('h3').attr("id")); 
    $('.class').children('h3').trigger('click'); 
}); 

var panels=""; //Creating JPanels on the fly 

var trs='<tr width="100%">'+ 
    '<th class="thPanel" align="left" width="40%">Database Type</th>'+ 
    '<td align="left" width="60%" style="word-break:break-all;">Something</td>'+ 
'</tr>'+ 
'<tr width="100%">'+ 
    '<th class="thPanel" align="left" width="40%">Database Version</th>'+ 
    '<td align="left" width="60%" style="word-break:break-all;">Something</td>'+ 
'</tr>'; 

panels+='<div title="Database Version" class="class">'+ 
    '<div class="jqUIDiv">'+ 
     '<table class="jpanelTable">'+ 
      '<tbody>'+trs+'</tbody>'+ 
     '</table>'+ 
    '</div>'+ 
'</div>'; 

panels+='<div title="ORS Databases" class="class" id="OrsDatabases">'+ 
    '<div class="jqUIDiv">'+ 
     '<table class="jpanelTable">'+ 
      '<tbody>'+trs+'</tbody>'+ 
     '</table>'+ 
    '</div>'+ 
'</div>'; 

panels+='<div title="Master Database" class="class">'+ 
    '<div class="jqUIDiv">'+ 
     '<table class="jpanelTable">'+ 
      '<tbody>'+trs+'</tbody>'+ 
     '</table>'+ 
    '</div>'+ 
'</div>'; 

$('#mainContent').empty(); 
$('<div>') 
.html('<div>'+panels) 
.appendTo('#mainContent').delay(10).queue(function(){ 
    $('.class').jPanel({ 
     'effect' : 'fade', 
     'speed'  : 'slow', 
     'easing' : 'swing' 
    });  
}); 

回答

0

最後我想出了東西,幫我

$('#triggerPanelBtn').click(function(){ 
    $('.class').each(function() { 
      if($(this).attr("title")==="ORS Databases") //I want to Expand/Collapse the JPanel having "ORS Databases" as it's Title 
      $(this).children('h3').trigger('click'); 
    }); 
}); 
+1

你可以這樣做:'this.title' –

1

您可以使用最新的JPanel 1.4版默認開啓功能,並指定面板像打開下面

$('#wrapperId').jPanel({ 
    "defaultOpen" : true 
      // other settings 
}); 

或如果你已經使用類選擇器初始化了面板,並希望單獨打開一些面板,使用按鈕上的標題,單擊你可以按照上面提到的那樣進行操作。