File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import $ from "jquery" ;
21import Base from "@patternslib/patternslib/src/core/base" ;
32import utils from "../../core/utils" ;
43
@@ -39,20 +38,29 @@ export default Base.extend({
3938 }
4039
4140 if ( self . options . data && typeof self . options . data === "string" ) {
42- self . options . data = $ . parseJSON ( self . options . data ) ;
41+ self . options . data = JSON . parse ( self . options . data ) ;
4342 }
4443 if ( self . options . onLoad !== null ) {
4544 // delay generating tree...
46- var options = $ . extend ( { } , self . options ) ;
45+ const options = { ...self . options } ;
46+
47+ try {
48+ const response = await fetch ( options . dataUrl ) ;
49+
50+ if ( ! response . ok ) {
51+ throw new Error ( "HTTP error " + response . status ) ;
52+ }
53+
54+ const data = await response . json ( ) ;
4755
48- $ . getJSON ( options . dataUrl , function ( data ) {
4956 options . data = data ;
5057 delete options . dataUrl ;
58+
5159 self . tree = self . $el . tree ( options ) ;
5260 self . options . onLoad ( self ) ;
53- } ) . fail ( function ( response ) { // eslint-disable-line no-unused-vars
54- console . log ( " failed to load json data" ) ;
55- } ) ;
61+ } catch ( error ) {
62+ console . log ( ` failed to load json data: ${ error } ` ) ;
63+ }
5664 } else {
5765 self . tree = self . $el . tree ( self . options ) ;
5866 }
You can’t perform that action at this time.
0 commit comments