在点击时获取dijit / titlepane的data-dojo-attachpoint

时间:2015-06-16 17:27:53

标签: javascript dojo dijit.form

我有一组dijit / titlepanes,我试图使其像手风琴一样(当一个人被点击时其他人关闭)。我已经能够使用下面代码中窗格的点击事件来完成此操作。问题是我需要将id分配给窗格才能使它工作。反正我是否可以在窗格的click事件中获取窗格的data-dojo-attachpoint?分配ID会产生问题,因为需要多次创建窗口小部件

小部件中标题栏的标记:

<div id="P1" data-dojo-attach-point="P1" data-dojo-type="dijit/TitlePane" 
data-dojo-props="title:'1: Step 1', closable:false,  open:false" data-dojo-attach-event="onClick:ClickPane"/>

<div id="P2" data-dojo-attach-point="P2" data-dojo-type="dijit/TitlePane" 
data-dojo-props="title:'2: Step 2', closable:false,  open:false" data-dojo-attach-event="onClick:ClickPane"/>

<div id="P3" data-dojo-attach-point="P3" data-dojo-type="dijit/TitlePane" 
data-dojo-props="title:'3: Step 3', closable:false,  open:false" data-dojo-attach-event="onClick:ClickPane"/>


<div id="P4" data-dojo-attach-point="P4" data-dojo-type="dijit/TitlePane" 
data-dojo-props="title:'4: Step4', closable:false,  open:false" data-dojo-attach-event="onClick:ClickPane"/>

代码:

 ClickPane: function (evt) {
            //close all other panes after one has been clicked
            var panesName = ["P1", "P2", "P3", "P4"];//ids
            var panes = [this.P1, this.P2, this.P3, this.P4];
            var pane = evt.currentTarget.id;//id like to be able to grab attachpoint here
            var index = panesName.indexOf(pane);
            if (index > -1) {
                panes.splice(index, 1);
                for (var i = 0; i < panes.length; i++) {
                    panes[i].set("open", false)
                }
            }

        },

我可以使用css手风琴,但我真的很喜欢这些标题窗格的外观和工作方式

由于

1 个答案:

答案 0 :(得分:0)

使用了dojox / widget / TitleGroup

工作得很好