我想听听不是我维护的 SPA 中的路径变化。
我在这里找到了一个解决方案:https : //stackoverflow.com/a/44819548/7042552
但是,对我来说似乎有点“hacky” - 但我的实现仍然是这样的:
let url = window.location.href;
['click','popstate', 'onload'].forEach( evt =>
window.addEventListener(evt, function () {
requestAnimationFrame(()=>{
if (url !== location.href) {
// do stuff
}
url = location.href;
});
}, true)
);
Run Code Online (Sandbox Code Playgroud)
是否有更好或更通用的方法来监听 SPA 中的页面加载?
我知道这个主题已经有多个问题https://stackoverflow.com/search?q=%5Bjavascript%5D+return+forEach+undefined但这些似乎都没有帮助我。
所以我有以下数据:
const testsMap = {
0: ["just", "test"],
1: ["bla", "asdf"]
}
const testArray = [{
id: "1",
segments: null,
tests: [{
id: "1",
segments: "1"
},
{
id: "2",
segments: "0"
}
]
},
{
id: "2",
segments: "1",
tutorials: [{
id: "1",
segments: "1"
},
{
id: "2",
segments: "0"
}
]
}];
Run Code Online (Sandbox Code Playgroud)
我想在不使用.map()或.reduce因为我不需要新数组的情况下通过输出实现的目标,我只想覆盖现有的数组,如下所示:
[{
display: true,
id: "1",
segments: null,
tests: [{
display: true,
id: "1",
segments: "1", …Run Code Online (Sandbox Code Playgroud)