File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -95,9 +95,11 @@ define(
9595
9696 function click ( e ) {
9797 var node = e . target ;
98+ var children = lib . getChildren ( this . main ) ;
9899 while ( node !== this . main ) {
99100 if ( this . helper . isPart ( node , 'node' ) ) {
100- var index = e . target . getAttribute ( 'data-index' ) ;
101+ var index = node . hasAttribute ( 'data-index' ) ? node . getAttribute ( 'data-index' )
102+ : getPathIndex ( children , node ) ;
101103 var event = this . fire ( 'click' , { item : this . path [ index ] } ) ;
102104 event . isDefaultPrevented ( ) && e . preventDefault ( ) ;
103105 return ;
@@ -107,6 +109,15 @@ define(
107109 }
108110 }
109111
112+ function getPathIndex ( children , node ) {
113+ for ( var i = children . length - 1 ; i > - 1 ; i -= 2 ) {
114+ if ( children [ i ] === node ) {
115+ // separator 的插入使得索引要除个2
116+ return i / 2 ;
117+ }
118+ }
119+ }
120+
110121 /**
111122 * 无链接的文字节点的内容HTML模板
112123 *
You can’t perform that action at this time.
0 commit comments