将自定义 JSON 文件作为数据加载到 A-frame 组件中的最佳方法是什么?例如,JSON 文件可能包含点的坐标。我想将文件作为 Assets 加载并在组件中使用解析的 json 对象。
{"coordinates": [{"x": 0, "y": 1, "z": 2}, // ...]}
最佳答案
您可以 define your own property type in the schema that parses data how you wish .
要从组件解析 JSON,请创建 parse
执行 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>
关于aframe - 如何将 JSON 数据加载到 A-Frame 组件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41545518/