我正在尝试使用框架框架制作360度视图。场景中会有几个面板(平面)。来自外部JSON文件的数据将显示在这些面板上。
以下是外部JSON文件中的一些数据:
"data": [
{
"id": 1,
"state_id": 1,
"name": "Titi Tinggi",
"code_name": "N1",
"type": "DUN",
"hot_seat": true,
"election_year": 2013,
"registered_voters": 9159,
"spoilt": 0,
"turnout": 7332,
"turnout_percent": 80,
"majority": 1486,
"majority_percent": 20,
"race_malay": 6734,
"race_chinese": 2128,
"race_india": 258,
"race_bumi": null,
"race_nonbumi": null,
"race_others": 54,
"state": {
"id": 1,
"name": "Perlis",
"code": "PER"
我尝试使用jquery来获取数据。它没有显示任何错误,但360图像有点“阻止”#39;数据。
AFRAME.registerComponent ('jsonreader',
{
init: function()
{
$.getJSON('seat_perlis.json', function(data) {
console.log(data);
$('#test').text(data.data[0].name);
});
}
});
我到处寻找解决方案。不幸的是,失败了。
答案 0 :(得分:0)
使用$('#test').text(json)
您正在创建HTML。来自常见问题解答,A-Frame cannot render raw HTML content。您必须使用<a-text/>
component之类的东西来生成与WebGL兼容的版本。
var el = document.createElement('a-text');
el.setAttribute('value', data.data[0].name);
sceneEl.appendChild(el);