aframe-jsonloader-component
Version:
Initializes aframe components using json
2 lines (1 loc) • 788 B
JavaScript
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?factory():typeof define==="function"&&define.amd?define(factory):factory()})(this,function(){"use strict";if(typeof AFRAME==="undefined"){throw new Error("Component attempted to register before AFRAME was available.")}AFRAME.registerComponent("jsonloader",{schema:{url:{type:"string",default:""}},multiple:false,init:function(){let data=this.data;let el=this.el;let callback=function(json){for(let i=0;i<json.length;i++){let r=json[i];let e=document.createElement("a-entity");Object.keys(r).forEach(function(key){let value=r[key];e.setAttribute(key,r[key]);e.setAttribute(key,r[key])});el.appendChild(e)}};fetch(data.url||"data/sample.json").then(response=>response.json()).then(json=>callback(json))}})});