springboot怎么把数据传给前端:springboot 如何引入前端 bootstrap?
这种问题网上一搜一大堆,你可以具体找一篇文章试试,遇到问题可以针对相关问题去提问。springboot通过jar包方式引入bootstrap_个人文章 - SegmentFault 思否 这不是查查就
顺晟科技
2022-10-18 14:11:16
227
我已经使用普通的JavaScript
创建了简单的Web组件。问题出在我的hideNonVisibleDivs()
上,我想访问shadowRoot
这是我的函数。
var visibleDivId = null;
var i, divId, div;
console.log('shadowroot', this); // display the global shadow root element
function divVisibility(divId) {
hideNonVisibleDivs.bind(this)(divId); //binding this context
}
function hideNonVisibleDivs(divId) {
//I want to access a shadow root here using this
console.log('shadowroot', this); //undefined
}
var panels = this.shadowRoot.querySelectorAll("#tab-info> .share-tab")
panels.forEach(function(el) {
divVisibility.bind(this)(this.getAttribute('custom-id')); //bind this context
});
});
预期是什么?
在hideNonVisibleDivs(divId)
中,我想将ShadowRoot作为外部函数(全局ShadowRoot)来访问,这意味着。
顺晟科技:
我能提供的最简单的解决方案是停止使用this
。this
的含义随着每个函数的调用而变化,这就是为什么您在理解代码中的任何一点时都很难理解它所指的内容。
例如,divVisibility()
函数无法工作。
console.log( 'shadowroot', this ); //{this} is a shadowroot
//...
function divVisibility(divId) {
//shadow root {this} cannot be accessed at all from here
hideNonVisibleDivs.bind(this)(divId); //binding this context
//^Refers to divVisibility
}
尝试在不使用this
的情况下重写代码。相反,请使用变量名称,如“ shadowroot ”。(不幸的是,在不了解代码的情况下,我不知道这个建议有多大用处。)
05
2022-12
02
2022-12
02
2022-12
29
2022-11
29
2022-11
24
2022-11