gpt4 book ai didi

javascript - 我如何将 touchevent 字符串化,忽略任何 DOM 引用?

转载 作者:行者123 更新时间:2023-11-29 21:02:23 25 4
gpt4 key购买 nike

我正在使用 UniWebView 作为 Unity 的 UI。我需要发送 touchevent 来修改 3D Assets 。 Uniwebview 的消息传递是通过 URL 格式完成的,因此必须是字符串。

当我尝试使用 JSON.stringify() 发送 touchevent 时,它只会发送 {isTrusted: true}。我已经完成了所有内容 this question没有运气。 second 中的函数和 third答案返回相同的结果,只有 isTrusted 对象。

在最上面的答案中,作者明确表示您不应删除所有 DOM 引用,但在我的用例中,我认为这是完全可以接受的。

我该怎么做?

如果它自动执行(检测它是否是 DOM 元素(“循环引用”))会很好,但我想我也可以手动过滤以下键:

  • changedTouches[x].目标
  • 当前目标
  • 路径[]
  • 源元素
  • 目标
  • targetTouches[x].目标
  • 触摸[x].目标
  • 查看

我找到了 this question用于递归循环对象,但注释暗示循环引用可能导致溢出。最重要的是,我不确定如何“重建”该对象。

如有任何帮助,我们将不胜感激。

最佳答案

不是解决方案,但暂时我只是找回触摸:

function getTouches(e) {
let touches = e.touches;
let output = [];
for (let i = 0; i < touches.length; i++) {
let touch = {
clientX: touches[i].clientX,
clientY: touches[i].clientY
};
output.push(touch);
}
return output;
}

关于javascript - 我如何将 touchevent 字符串化,忽略任何 DOM 引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45888285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com