我有setAttribute的問題。我設置了一個數組作爲旋轉的值,但它不起作用。 gradRoll
的提醒是number
。但是gradRoll
的類型是undefined
。爲什麼?有誰能夠幫助我?提前致謝。js setAttribute與Array
AFRAME.registerComponent('clockhand_roll',{
schema:{
type:'string', default: "secondClockhand"
},
init:function(){
var data = this.data;
var el=this.el;
var oTime= new Date();
var curTime;
var clockhandPositonArray;
if(data == "secondClockhand"){
curTime = oTime.getSeconds();
}else if(data == "minuteClockhand"){
curTime = oTime.getMinutes();
}else if(data == "hourClockhand"){
curTime = oTome.getHours;
}else {
alert("invalid input!");
}
//alert(curTime);
//clockhandPositonArray=getClockhandPosition(curTime, data);
//alert(el.getAttribute("rotation"));
//el.setAttribute("rotation", 'clockhandPositonArray');
setClockhandPosition(el, curTime, data);
}
});
function setClockhandPosition(el, curTime, typeOfClockhand){
var gradForOneUnit;
var gradRoll;
var rotationArray;
if(typeOfClockhand == "secondClockhand" || typeOfClockhand == "minuteClockhand"){
gradForOneUnit=360/60;
}else if(typeOfClockhand == "hourClockhand"){
gradForOneUnit=360/12;
}
gardRoll=curTime*gradForOneUnit;
//alert(gardRoll); //number: 354!!!!!!!!!!!!!!!!!!!! why??????
//alert(typeof(gradRoll)); //undefined!!!!!!!!!!!!! why??????
rotationArray=[curTime*gradForOneUnit, 0, 0];
//alert(typeof(rotationArray));//object
//alert(typeof(el.getAttribute("rotation"))); //object
//alert(rotationArray); //number: 162 , 0, 0
el.setAttribute("rotation", rotationArray); //dosn't work.
}
查找錯別字' gradRoll/gardRoll' –
@Nathan P. thanks –
rotationArray = {x:curTime * gradForOneUnit,y:0,z:0};它的工作原理 –