@@ -147,13 +147,20 @@ export class FancytreeAdapter {
147
147
// transform the JSON response into a data structure that's supported by FancyTree
148
148
postProcess : function ( event , data ) {
149
149
if ( null == data . error ) {
150
- data . result = requestNodeToFancytreeNode ( data . response ) . children ;
151
- if ( data . result . length == 1 ) {
152
- data . result [ 0 ] . expanded = true ;
150
+ var result = requestNodeToFancytreeNode ( data . response ) ;
151
+ if ( "" === result . key ) {
152
+ result = result . children ;
153
+ } else {
154
+ result = [ result ] ;
155
+ }
156
+
157
+ if ( result . length == 1 ) {
158
+ result [ 0 ] . expanded = true ;
153
159
}
154
160
161
+ data . result = result ;
155
162
if ( useCache ) {
156
- cache . set ( data . node . getKeyPath ( ) , data . result ) ;
163
+ cache . set ( data . node . getKeyPath ( ) , result ) ;
157
164
}
158
165
} else {
159
166
data . result = {
@@ -182,14 +189,15 @@ export class FancytreeAdapter {
182
189
}
183
190
184
191
bindToInput ( $input ) {
192
+ var root = this . rootNode ;
193
+ if ( root . substr ( - 1 ) == '/' ) {
194
+ var root = this . rootNode . substr ( 0 , - 1 ) ;
195
+ }
196
+ var rootParent = root . substr ( 0 , root . lastIndexOf ( '/' ) ) ;
197
+
185
198
// output active node to input field
186
199
this . $tree . fancytree ( 'option' , 'activate' , ( event , data ) => {
187
- root = this . rootNode ;
188
- if ( root . substr ( - 1 ) == '/' ) {
189
- var root = this . rootNode . substr ( 0 , - 1 ) ;
190
- }
191
-
192
- $input . val ( root + data . node . getKeyPath ( ) ) ;
200
+ $input . val ( rootParent + data . node . getKeyPath ( ) ) ;
193
201
} ) ;
194
202
195
203
var showKey = ( key ) => {
@@ -201,8 +209,8 @@ export class FancytreeAdapter {
201
209
} ) ;
202
210
} ;
203
211
var removeRoot = ( path ) => {
204
- if ( 0 === path . indexOf ( this . rootNode ) ) {
205
- return path . substr ( this . rootNode . length ) ;
212
+ if ( 0 === path . indexOf ( rootParent + '/' ) ) {
213
+ return path . substr ( rootParent . length + 1 ) ;
206
214
}
207
215
208
216
return path ;
0 commit comments