事前にお詫び申し上げます。私はReactを非常に新しくしています。 printDocument
でイベントにメソッドを代入するときに「this」にアクセスする
私もthis.setPrint
からoHiddFrame.onload = this.setPrint;
を設定していますが、最初の割り当てにsetPrint
にthis
ためCannot set property '__container__' of undefined
のエラーを取得しています。
render()内のボタンにonClick={this.printDocument.bind(null, this.props.document.view_href)}
を設定しています。私はそれに割り当てている実際のイベントに "これ"をバインドするにはどうすればいいですか?
多くのヘルプやアドバイスに感謝します。それ以外の場合は、正しくボタンに結合しない、onClick={this.printDocument.bind(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);
},