Javascript 如何使用getAttribute传递组件中定义的值,而不是框架标记属性? 问题:

Javascript 如何使用getAttribute传递组件中定义的值,而不是框架标记属性? 问题:,javascript,html,components,aframe,getattribute,Javascript,Html,Components,Aframe,Getattribute,在aframe组件score中,我需要从组件timer获取当前time值以计算分数 但是,使用getAttribute方法返回NaN值或[object object] 我已尝试将时间变量从计时器传递到分数,但是分数的值要么未更改,要么显示为NaN或[object object]。我对js和aframe还比较陌生,所以如果我的代码很混乱,我深表歉意 注: 为了简单起见,代码中没有包括许多实体 JS组件: HTML标记: AFRAME.registerComponent('ti

在aframe组件
score
中,我需要从组件
timer
获取当前
time
值以计算分数

但是,使用
getAttribute
方法返回
NaN
值或
[object object]

我已尝试将
时间
变量从
计时器
传递到
分数
,但是
分数
的值要么未更改,要么显示为
NaN
[object object]
。我对js和aframe还比较陌生,所以如果我的代码很混乱,我深表歉意

注: 为了简单起见,代码中没有包括许多实体

JS组件: HTML标记:

         AFRAME.registerComponent('timer', {
                schema:{
                    value:{default: 60},
                },

                init: function B() {
                    var data = this.data;
                    var el = this.el; 
                    var time = 60;
                    if(time == 60 || time == 0){
                        start_b.addEventListener('click', function() {
                            setInterval(() => {
                                if(time > 0){
                            time--
                            el.setAttribute('text', 'value', time);};
                            }, 1000);
                    })}
                }});

            AFRAME.registerComponent('score', {
                  schema: {
                    el: {type: 'selector'},
                    score:{type: 'int', default: 0},
                },

            init: function () {
                var newScore = 0;
                var sceneEl = document.querySelector('a-scene'); 
                var scoreBoard = document.querySelector('#score_t');
                sceneEl.querySelector('#mix_b').addEventListener('click', () => {
                    var colorOutput = document.querySelector('#box');
                    var colorFrame = document.querySelector('#colorBox');
                    var timeDisplayV = document.querySelector('#timeDisplay');
                    var timeDisplayn = timeDisplayV.getAttribute('text', 'value');
                    var colorAsked = colorFrame.getAttribute('color');
                    var colorMade = colorOutput.getAttribute('color');

                    if(colorMade == colorAsked){
                        var timeDisplayn = timeDisplayV.getAttribute('text', 'value');
                        this.data.score = timeDisplayn
                        newScore = 'Score: ' + this.data.score
                        scoreBoard.setAttribute('text','value', newScore);
                    }
                });

                clear_b.addEventListener('click', function () {
                    el.setAttribute("color", "#ffffff");
                    });
                }
            });
            <a-entity 
                id="score_t"
                text="value: Score: 0"
                position="0.7 0.45 -1" >
            </a-entity>

            <a-text 
                id="timeDisplay"
                timer="value:" 
                position="0.7 0.65 -1" 
                scale="0.3 0.3 0.3">
            </a-text>