提前道歉,我对 React 很陌生。
在printDocument
我设置oHiddFrame.onload = this.setPrint;
甚至this.setPrint
,但我得到的误差Cannot set property '__container__' of undefined
为this
在setPrint
第一个任务。
我正在onClick={this.printDocument.bind(null, this.props.document.view_href)}
渲染()中的按钮上设置。如何将“this”绑定到我分配给它的实际事件?
非常感谢任何帮助或建议。
closePrint: function () {
document.body.removeChild(this.oHiddFrame.__container__);
},
setPrint: function () {
this.contentWindow.__container__ = this;
this.contentWindow.onbeforeunload = this.closePrint;
this.contentWindow.onafterprint = this.closePrint;
this.contentWindow.focus();
this.contentWindow.print();
},
printDocument: function (url) {
var oHiddFrame = document.createElement("iframe");
oHiddFrame.onload = this.setPrint;
oHiddFrame.style.visibility = "hidden";
oHiddFrame.style.position = "fixed";
oHiddFrame.style.right = "0";
oHiddFrame.style.bottom = "0";
oHiddFrame.src = url;
document.body.appendChild(oHiddFrame);
},