【发布时间】:2021-05-05 10:33:50
【问题描述】:
在我的代码中,当我选择行并单击按钮然后此网址打开 http://codeskulptor-assets.commondatastorage.googleapis.com/assets_clock_minute_arrow.png 时,我正在尝试执行此操作。
但是现在在我的代码中,当我选择行并单击按钮时,url 没有打开。
当我选择行并单击打开 URL http://codeskulptor-assets.commondatastorage.googleapis.com/assets_clock_minute_arrow.png 的按钮时,我们如何才能打开此 URL。
我的代码在这里https://codesandbox.io/embed/react-example-forked-o8tu5?codemirror=1
请任何人提出任何想法并帮助我。我坚持这一点。
import React from 'react';
import axios from 'axios';
class ProvFileRptSearchResult extends React.Component {
constructor(props) {
super();
this.state = {
pymtDetails:[],
data: [],
rowDetails:[],
checkbox: false
};
// this.handleFile=this.handleFile.bind(this);
this.handleClick=this.handleClick.bind(this);
}
handleClick() {
const apiUrl = "http://localhost:9090/PrvFileRpt/getPrvFileData";
if (this.state.checkbox) {
fetch(apiUrl)
.then((response) => response.json())
.then((data) => {
this.setState({ data: data });
console.log("This is your data", data);
window.open("https://example.com", "_blank");
})
} else {
alert("Data not fetched!");
}
// console.log('click');
}
// handleClick(e) {
// e.preventDefault();
// console.log("The link was clicked");
// }
// handleFile()
// {
// //fetch birt report from here
// console.log("inside file ",this.state.rowDetails);
// }
rowSelected(j) {
// e.preventDefault();
console.log(j)
const rownum=j;
console.log("rownum=",rownum)
console.log(this.props.customerDetails[rownum] )
this.setState({rowDetails:this.props.customerDetails[rownum]}, () => {
});
}
render()
{
return(
<div>
<div className="table-employee" style={{ marginTop:"20px",border:" 1.5px solid darkgray" }}>
<table className="table table-hover table-bordered table-sm">
<thead>
<tr >
<th scope="col">Select</th>
<th scope="col"> LOAD DATE</th>
<th scope="col"> FILE DATE</th>
<th scope="col"> SERVICE</th>
<th scope="col"> PROVISIONER CODE </th>
<th scope="col"> DESCRIPTION</th>
</tr>
</thead>
<tbody>
{
this.props.customerDetails.map((type,j)=>{
return(
<tr>
<td ><input type="radio" preventDefault name="select" key={j} onClick={(e) =>this.rowSelected(j)} value={this.state.checkbox}
onChange={(e) =>
this.setState({ checkbox: !this.state.checkbox })
}/></td>
<td> {type.provis_file_stamp}</td>
<td> {type.provis_file_hdrdt}</td>
<td> {type.service_code}</td>
<td>{type.provisioner_code}</td>
<td>{type.provisioner_desc}</td>
</tr>
)
})
}
</tbody>
</table>
</div>
<div className="btn-submit" >
<button className="btn btn-primary" style={{marginRight:"30px"}} type="submit" onClick={this.handleClick}>FILE</button>
</div>
</div>
)
}
}
export default ProvFileRptSearchResult;
【问题讨论】:
-
任何机构都建议我任何想法codesandbox.io/embed/react-example-forked-o8tu5?codemirror=1我的代码
-
请不要仅仅张贴codesandbox的链接让我们帮助您。在问题中包含一个最小示例
-
您确定要打开该网址吗?也许您想在页面上显示该图像?
-
是的openurl链接
-
不,我想打开网址
标签: javascript reactjs