我做了一个A帧360度视图。我从一个名为
seat_perlis.json
. 现在我想在场景中制作一系列面板。下面是我的jQuery代码。
<script>
AFRAME.registerComponent ('jsonreader',
{
init: function()
{
var sceneEl = document.querySelector('a-scene');
var el = document.createElement('a-text');
$.getJSON( "seat_perlis.json", function( response ) {
console.log(response);
//push data to items
$.each( response.data, function( key, val ) {
$('#jadah').append(`\
<a-entity layout="type: box; margin: 1.6" scale="0.8 0.8" position="0 -1 -4">\
<a-text value='${val.name} \n ${val.code_name} \n ${val.candidate_seats[0].candidate.name}' color="red" id="entity1-1"></a-text>\
</a-entity>\
`);
});//end each
}); //end getJSON
}
});
下面是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"
},
"candidate_seats": [
{
"id": 1,
"candidate_id": 2538,
"seat_id": 1,
"party_id": 1,
"verified_vote": 3925,
"unverified_vote": null,
"status": "WON",
"candidate": {
"id": 2538,
"name": "Khaw Hock Kong",
"image": null
}
},
{
"id": 2,
"candidate_id": 2540,
"seat_id": 1,
"party_id": 100,
"verified_vote": 968,
"unverified_vote": null,
"status": null,
"candidate": {
"id": 2540,
"name": "Yaacob Bin Man",
"image": null
}
},
{
"id": 3,
"candidate_id": 2539,
"seat_id": 1,
"party_id": 300,
"verified_vote": 2439,
"unverified_vote": null,
"status": "",
"candidate": {
"id": 2539,
"name": "Teh Seng Chuan",
"image": null
链接是预期结果->
[图片][1]
现在JSON数据已经存在,但它直接上升了。我不知道怎么打破它。