A reusable kind for Enyo 2.0 to open a JSON file.
enyo.kind({ name: "FileLoad", kind: enyo.WebService, jsonp: false, published: { fileName: "", data: [] }, events: { onSuccess: "" }, handlers:{ onResponse: "querySuccess", onError: "queryFail" }, fileNameChanged: function() { this.url = "data/" + this.fileName + ".json"; }, querySuccess: function(inSender, inResponse) { this.data = inResponse.data; this.doSuccess({file: this.fileName, data: inResponse.data}); }, queryFail: function(inSender, inResponse){ enyo.log("Error while loading up the tense.json data file.", inResponse ); this.data = []; } });
And sample code on how to successfully call it. You can also set the Url directly and avoid the file name property.
components: [ { kind: "FileLoad", onSuccess: "tenseLoaded" }, ], rendered: function( ){ this.inherited(arguments); this.$.tenseData.setFileName("tense"); this.$.tenseData.send( ); }, tenseLoaded : function( inSender, inEvent){ this.setCount(inEvent.data.length); this.reset(); },