更新未在 aframe 组件中触发
update is not firing in aframe component
我从 aframe 文档中了解到,每当我们更新位置或任何其他值时,附加组件的更新都会触发,我只是想在每次位置更改时触发更新。
这是组件:-
AFRAME.registerComponent('checking', {
init: function(){
console.log("initialized");
},
update: function(){
console.log("valueUpdated: "+this.el.id);
},
tick: function(){
}
});
更新在加载文档时使用 init 触发一次,但当我从控制台执行此操作时不会像 obj.setAttribute("position","4 6 7");
根据文档,它应该是正确的,或者我犯了一些非常基本的错误?
谢谢...
我认为您混淆了组件和实体。实体是一个容器,其行为和外观是通过组件定义的。
所以更新函数在开始时触发 + 当您更改组件时,例如通过 setAttribute('checking','newValue').
您可以通过以下方式进行检查:
包括 'componentChanged' 事件的侦听器:
this.el.addEventListener('componentChanged',function(e){
if(e.detail.name==='position'){
console.log(e.detail.newData);
}
});
检查仓位是否在逐笔报价时发生变化,但这似乎非常无效:
init(){
this.pos = this.el.getAttribute('position');
}
tick: function(){
if( this.el.getAttribute('position') != this.pos ){
this.pos = this.el.getAttribute('position');
}
}
我从 aframe 文档中了解到,每当我们更新位置或任何其他值时,附加组件的更新都会触发,我只是想在每次位置更改时触发更新。
这是组件:-
AFRAME.registerComponent('checking', {
init: function(){
console.log("initialized");
},
update: function(){
console.log("valueUpdated: "+this.el.id);
},
tick: function(){
}
});
更新在加载文档时使用 init 触发一次,但当我从控制台执行此操作时不会像 obj.setAttribute("position","4 6 7");
根据文档,它应该是正确的,或者我犯了一些非常基本的错误?
谢谢...
我认为您混淆了组件和实体。实体是一个容器,其行为和外观是通过组件定义的。
所以更新函数在开始时触发 + 当您更改组件时,例如通过 setAttribute('checking','newValue').
您可以通过以下方式进行检查:
包括 'componentChanged' 事件的侦听器:
this.el.addEventListener('componentChanged',function(e){
if(e.detail.name==='position'){
console.log(e.detail.newData);
}
});
检查仓位是否在逐笔报价时发生变化,但这似乎非常无效:
init(){
this.pos = this.el.getAttribute('position');
}
tick: function(){
if( this.el.getAttribute('position') != this.pos ){
this.pos = this.el.getAttribute('position');
}
}