我使用下面的代码来显示记录.但我目前的问题是我无法将reactjs值传递给Image标签和链接标签,如下面的代码行所示.
<img src=/uploads/{item.pic}></img>
<a href="data.php?id={item.link}" tittle="">Next</a>
Run Code Online (Sandbox Code Playgroud)
这可能是最好的方法
class App extends React.Component {
constructor(){
super()
this.state = {
data: []
}
}
componentDidMount() {
$.ajax({
url: "jeck.php",
type: "GET",
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(jqXHR) {
console.log(jqXHR);
}.bind(this)
})
}
render() {
return (
<div>
{this.state.data.map(function(item, key) {
return (
<li key={key}>
{item.name}
{item.id}
{item.pic}
{item.link}
<img src=/uploads/{item.pic}></img>
<a href="data.php?id={item.link}" tittle="">Next</a>
</li>
);
})}
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud) reactjs ×1