嘿,我又遇到了一点麻烦,我应该在 airtable 中放一个问题列表,然后将它们打印到我的屏幕上,但我正在使用 fetch reqeust en then e get 方法,但我感觉我的空变量是没有被我的问题填满
顺便说一句,它在javascript中:
这是我的代码:
; (function (){
window.addEventListener('load', function(){
document.getElementById('next').addEventListener('click', function(){
window.location.href = 'vragenlijst2.html';
})
let vrg1 = document.getElementById('1vraag');
let vrg2 =document.getElementById('2vraag');
let vrg3 = document.getElementById('3vraag');
let vrg4 = document.getElementById('4vraag');
let vrg5 = document.getElementById('5vraag');
let vrg6 = document.getElementById('6vraag');
let vrg7 = document.getElementById('7vraag');
let vrg8 = document.getElementById('8vraag');
let vrg9 = document.getElementById('9vraag');
let vrg10 = document.getElementById('10vraag');
let Vragenlijst_id = 1;
let getData = function(){
fetch('https://api.airtable.com/v0/appojP2iMG4i3P61S/EDBL', {
method: 'GET',
headers: {
'Authorization' : 'Bearer keyDhD8sLGjcEuA4K'
}
})
.then(Response => Response.json())
.then(JSON => {
console.log(JSON)
for(let index = 0; index < JSON.records.length; index++){
let Qstn = JSON.records[index];
if(Vragenlijst_id === Qstn.fields.vragenlijst){
let vrg1_db = Qstn.fields.Vraag1;
let vrg2_db = Qstn.fields.Vraag2;
let vrg3_db = Qstn.fields.Vraag3;
let vrg4_db = Qstn.fields.Vraag4;
let vrg5_db = Qstn.fields.Vraag5;
let vrg6_db = Qstn.fields.Vraag6;
let vrg7_db = Qstn.fields.Vraag7;
let vrg8_db = Qstn.fields.Vraag8;
let vrg9_db = Qstn.fields.Vraag9;
let vrg10_db = Qstn.fields.Vraag10;
vrg1 = vrg1_db;
vrg2 = vrg2_db;
vrg3 = vrg3_db;
vrg4 = vrg4_db;
vrg5 = vrg5_db;
vrg6 = vrg6_db;
vrg7 = vrg7_db;
vrg8 = vrg8_db;
vrg9 = vrg9_db
vrg10 = vrg10_db;
console.log(vrg1);
}
}
})
}
getData();
function create (){
let par = document.createElement('p');
par.innerHTML = vrg1;
document.getElementById('1vraag').appendChild(par);
}
document.getElementById('1vraag').innerHTML = create()