如何将JSON数据加载到A-Frame组件中? [英] How to load JSON data into an A-Frame component?
本文介绍了如何将JSON数据加载到A-Frame组件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将自定义JSON文件作为数据加载到A框架组件中的最佳方法是什么?例如,JSON文件可能包含点的坐标。我想将文件作为资产加载,并在组件中使用已解析的json对象。
What's the best way to load a custom JSON file as data into an A-frame component ? For example, the JSON file may contain coordinates of points. I want to load the file as an asset and use the parsed json object in the component.
{"coordinates": [{"x": 0, "y": 1, "z": 2}, // ...]}
推荐答案
要从组件解析JSON,请创建 parse
函数,该函数执行 JSON.parse
:
To parse JSON from a component, create a parse
function that does a JSON.parse
:
AFRAME.registerComponent('foo', {
schema: {
jsonData: {
parse: JSON.parse,
stringify: JSON.stringify
}
}
});
然后使用组件:
el.setAttribute('foo', 'jsonData', yourJsonData);
或:
<a-entity foo='jsonData: {"coordinates": [{"x": 0, "y": 1, "z": 2}]}'></a-entity>
这篇关于如何将JSON数据加载到A-Frame组件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文