App.js
import React, {Component} from 'react';
import {render} from 'react-dom';
const source = "http://localhost:3000/";
class App extends Component {
state = { authors: [] };
static defaultProps = {
source: ''
};
static propTypes() {
source: React.PropTypes.string
};
loadAuthors() {
fetch(source)
.then(response => response.json())
.then(data => this.setState({ authors: data }))
.catch(err => console.error(source, err.toString()))
}
componentDidMount() {
this.loadAuthors()
}
render() {
const renderData = this.state.authors.map(function(author) {
return (
<div>
<p>author.id</p>
<p>author.firstName</p>
<p>author.lastName</p>
</div>
)
});
return (
<div>
<h1>
Welcome to the react starter!
</h1>
<h1>
{renderData}
</h1>
</div>
);
}
}
render(<App />, document.getElementById('root'));
JSON来源
{
authors: [
{
id: "zarghon-shah",
firstName: "Zarghon",
lastName: "Shah"
},
{
id: "khpalwalk-pashtun",
firstName: "Khpalwalk",
lastName: "Pashtun"
},
{
id: "sazinda-khudai",
firstName: "Sazinda",
lastName: "Khudai"
}
]
}
提前致谢
答案 0 :(得分:1)
看起来您需要在对“author”的引用周围放置JSX花括号,以便插值正确发生:
button.addTarget(self, action: ControlSelector.clearTapped, forControlEvents: .TouchUpInside)
否则你只是写出文字字符串“author.id”等。