如何在点击时切换折叠式容器?

时间:2013-02-26 17:51:38

标签: javascript widget onclick dojo

我有一个使用带有两个子容器的dijit.layout.AccordionContainer的应用程序。

加载地图时,默认情况下会打开其中一个容器。我希望关闭默认容器,单击按钮时打开第二个容器。知道怎么做吗?

我尝试过使用selectChild()方法,但一定是做错了还是我完全偏离了基础?

编辑我的HTML是:

<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>

我正试图打开“tab2”点击通过我创建的功能,我需要点击其他一些事情

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 个答案:

答案 0 :(得分:1)

听起来你正试图使用​​AccordionContainer#selectChild方法。通过按如下方式设置Button的onClick处理程序,这应该很容易处理:

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

其中"pane2“是您想要在按钮点击时打开的ContentPane的ID,而true表示您希望打开窗格的动画。您可以看到一个示例this fiddle