How to switch an AccordionContainer on click?

为君一笑 提交于 2019-12-11 10:52:16

问题


I have an app that uses a dijit.layout.AccordionContainer with two child containers.

When the map is loaded, one of the containers is open by default. I would like the default container to close and the second container to open when a button is clicked. Any idea how to do this?

I have tried using the selectChild() method but must be doing it wrong or am I completely off base?

EDIT My HTML is:

<div dojotype="dijit.layout.ContentPane" id="leftPane" region="left" splitter="true">
   <div dojotype="dijit.layout.AccordionContainer">
      <div dojotype="dijit.layout.ContentPane" title="Table of Contents">
           <div id="tocDiv"></div>
      </div>
      <div dojotype="dijit.layout.ContentPane" title="Search Results" id="tab2">
           <div id="datagrid">
                <table data-dojo-type="dojox.grid.DataGrid" data-dojo-id="grid"  id="grid" data-dojo-props="rowsPerPage:'5', rowSelector:'20px'">
                     <thead>
                         <tr>
                            <th field="Parcel Identification Number" width="25%">Parcel ID/th>
                            <th field="Site Address" width="30%"> Address </th>
                         </tr>
                     </thead>
                 </table>
             </div>
           </div>
    </div>
</div>

where I am trying to open "tab2" on click via a function I have created for some other things I need to happen on click

JS:

function doFind() {             
     //Set the search text to the value in the box
     findParams.searchText = dojo.byId("parcel").value;
     grid.showMessage("Loading..."); //Shows the Loading Message until search results are returned.
     findTask.execute(findParams,showResults);
}

回答1:


It sounds like you are on the right track trying to using the AccordionContainer#selectChild method. This should be easy to handle by setting your Button's onClick handler as follows:

onClick: function(){
    var container = dijit.byId("container");
    container.selectChild("pane2", true); 
}

Where "pane2" is the id of the ContentPane that you want to open on button click, and true indicates that you want the opening of the pane to be animated. You can see an example in this fiddle.



来源:https://stackoverflow.com/questions/15095893/how-to-switch-an-accordioncontainer-on-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!