@@ -221,53 +221,55 @@ JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({
221
221
items = vars [ this . enumSource [ i ] . source ] ;
222
222
}
223
223
224
- // Only use a predefined part of the array
225
- if ( this . enumSource [ i ] . slice ) {
226
- items = Array . prototype . slice . apply ( items , this . enumSource [ i ] . slice ) ;
227
- }
228
- // Filter the items
229
- if ( this . enumSource [ i ] . filter ) {
230
- var new_items = [ ] ;
231
- for ( j = 0 ; j < items . length ; j ++ ) {
232
- if ( this . enumSource [ i ] . filter ( { i :j , item :items [ j ] } ) ) new_items . push ( items [ j ] ) ;
233
- }
234
- items = new_items ;
235
- }
236
-
237
- var item_titles = [ ] ;
238
- var item_values = [ ] ;
239
- for ( j = 0 ; j < items . length ; j ++ ) {
240
- var item = items [ j ] ;
241
-
242
- // Rendered value
243
- if ( this . enumSource [ i ] . value ) {
244
- item_values [ j ] = this . enumSource [ i ] . value ( {
245
- i : j ,
246
- item : item
247
- } ) ;
224
+ if ( items ) {
225
+ // Only use a predefined part of the array
226
+ if ( this . enumSource [ i ] . slice ) {
227
+ items = Array . prototype . slice . apply ( items , this . enumSource [ i ] . slice ) ;
248
228
}
249
- // Use value directly
250
- else {
251
- item_values [ j ] = items [ j ] ;
229
+ // Filter the items
230
+ if ( this . enumSource [ i ] . filter ) {
231
+ var new_items = [ ] ;
232
+ for ( j = 0 ; j < items . length ; j ++ ) {
233
+ if ( this . enumSource [ i ] . filter ( { i :j , item :items [ j ] } ) ) new_items . push ( items [ j ] ) ;
234
+ }
235
+ items = new_items ;
252
236
}
253
237
254
- // Rendered title
255
- if ( this . enumSource [ i ] . title ) {
256
- item_titles [ j ] = this . enumSource [ i ] . title ( {
257
- i : j ,
258
- item : item
259
- } ) ;
260
- }
261
- // Use value as the title also
262
- else {
263
- item_titles [ j ] = item_values [ j ] ;
238
+ var item_titles = [ ] ;
239
+ var item_values = [ ] ;
240
+ for ( j = 0 ; j < items . length ; j ++ ) {
241
+ var item = items [ j ] ;
242
+
243
+ // Rendered value
244
+ if ( this . enumSource [ i ] . value ) {
245
+ item_values [ j ] = this . enumSource [ i ] . value ( {
246
+ i : j ,
247
+ item : item
248
+ } ) ;
249
+ }
250
+ // Use value directly
251
+ else {
252
+ item_values [ j ] = items [ j ] ;
253
+ }
254
+
255
+ // Rendered title
256
+ if ( this . enumSource [ i ] . title ) {
257
+ item_titles [ j ] = this . enumSource [ i ] . title ( {
258
+ i : j ,
259
+ item : item
260
+ } ) ;
261
+ }
262
+ // Use value as the title also
263
+ else {
264
+ item_titles [ j ] = item_values [ j ] ;
265
+ }
264
266
}
267
+
268
+ // TODO: sort
269
+
270
+ select_options = select_options . concat ( item_values ) ;
271
+ select_titles = select_titles . concat ( item_titles ) ;
265
272
}
266
-
267
- // TODO: sort
268
-
269
- select_options = select_options . concat ( item_values ) ;
270
- select_titles = select_titles . concat ( item_titles ) ;
271
273
}
272
274
}
273
275
0 commit comments