用 Javascript 修改组件架构数据值?
Modify component schema data value with Javascript?
AFRAME.registerComponent("myComponent", {
schema: {
myVar: {
type: "string",
default: "default value"
}
},
init: function () {
var self=this;
this.data.myVar="test";
console.log(this.data.myVar); // "test"
this.el.addEventListener("myEvent", function () {
console.log(self.data.myVar); // "default value"
});
}
});
我想修改数据组件的值,但是当我在一个事件中时,我只得到默认值。
怎么做?
谢谢:)
el.setAttribute('myComponent', 'myVar', value)
AFRAME.registerComponent("myComponent", {
schema: {
myVar: {
type: "string",
default: "default value"
}
},
init: function () {
var self=this;
this.data.myVar="test";
console.log(this.data.myVar); // "test"
this.el.addEventListener("myEvent", function () {
console.log(self.data.myVar); // "default value"
});
}
});
我想修改数据组件的值,但是当我在一个事件中时,我只得到默认值。
怎么做?
谢谢:)
el.setAttribute('myComponent', 'myVar', value)