使用 .flushToDom 导出场景数据,"event attributes" 数据出现问题

scene data export with .flushToDom, problems with "event attributes" data

我正在编写用于将场景数据发送到服务器的脚本。 为了逃避属性解析,我使用

.flushToDom()

这是一个问题。 他解析了一些属性的数据,比如字符串“[Object object]”

好的。我有 var 存储场景的位置。我正在尝试手动更改事件数据:

 document.querySelector('a-scene').flushToDOM(true);
 var cursor = scene.getElementsByTagName('a-cursor')[0];

 //console: [object Object]
 console.log(cursor.getAttribute('event-set__1'));
 cursor.setAttribute('event-set__1','_event: mouseenter; color: springgreen');

 //console: undefined    
 console.log(cursor.getAttribute('event-set__1'));
 cursor.setAttribute('event-set__2','_event: mouseleave; color: black');

但是,这并没有帮助。那么,我如何在不激活她的情况下设置事件的数据?

UPDATED after Piotr Adam Milewski comment

为了保存属性数据,我们需要在.flushToDom()之前克隆节点, 然后我们就可以修改属性了。

var cursor = document.getElementsByTagName('a-cursor')[0];
var cursorClone = cursor.cloneNode(true);
var cursorParent = cursor.parentNode;

document.querySelector('a-scene').flushToDOM(true);

cursorClone.setAttribute("event-set__1", {"_event": "mouseenter", "material.color": "springgreen"});
cursorClone.setAttribute("event-set__2", {"_event": "mouseleave", "material.color": "black"});

cursorParent.removeChild(cursor);
cursorParent.appendChild(cursorClone);

而不是

cursor.setAttribute('event-set__2','_event: mouseleave; color: black');

尝试

this.el.setAttribute("event-set__2", {
    "_event": "mouseenter",
    "material.color": "red"
})

应该是working