PrimeReact TieredMenu - uncatch TypeError: 无法读取 TieredMenu.show (TieredMenu.js:84) 上未定义的属性"currentTa



https://primefaces.org/primereact/showcase/#/tieredmenu

错误:-

Uncaught TypeError: Cannot read property 'currentTarget' of undefined
at TieredMenu.show (TieredMenu.js:84)
at TieredMenu.toggle (TieredMenu.js:65)
at dropdown._this.showDrp (dropdown.jsx:388)

TieredMenu.js:84 TieredMenu.js:65

_createClass(TieredMenu, [{
key: "toggle",
value: function toggle(event) {
if (this.props.popup) {
if (this.container.offsetParent) this.hide(event);else this.show(event);
}
}
}, {
key: "show",
value: function show(event) {
var _this = this;
if (this.props.autoZIndex) {
this.container.style.zIndex = String(this.props.baseZIndex + _DomHandler.default.generateZIndex());
}
this.container.style.display = 'block';
setTimeout(function () {
_DomHandler.default.addClass(_this.container, 'p-menu-overlay-visible');
_DomHandler.default.removeClass(_this.container, 'p-menu-overlay-hidden');
}, 1);
_DomHandler.default.absolutePosition(this.container, event.currentTarget);
this.bindDocumentListeners();
if (this.props.onShow) {
this.props.onShow(event);
}
}
}, 

dropdown.jsx

menu = React.createRef();
showDrp = () => {
var refs = this.menu;
if (refs && refs.current) refs.current.toggle();  // <-====
}
< i className="p-icon kr-ellipsis" onClick={(e) => this.showDrp()} aria-haspopup aria-controls="overlay_tmenu"></i>

<div className="dropDownBoX">
<TieredMenu model={obj} popup ref={this.menu} id="overlay_tmenu" />
</div>

此错误表示您没有将事件对象传递到toggle函数中。您需要稍微修改代码,以便在单击按钮时触发的事件进入toggle函数。

menu = React.createRef();
showDrp = (e) => {
var refs = this.menu;
if (refs && refs.current) refs.current.toggle(e); // <-====
};
<i
className="p-icon kr-ellipsis"
onClick={this.showDrp}
aria-haspopup
aria-controls="overlay_tmenu"
></i>;

<div className="dropDownBoX">
<TieredMenu model={obj} popup ref={this.menu} id="overlay_tmenu" />
</div>;

相关内容

  • 没有找到相关文章