我试图摆脱这个错误消息,但仍然没有成功.
Warning: A component is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component.
Run Code Online (Sandbox Code Playgroud)
还有链接到Facebook页面,但我仍然不知道如何弄明白.
class EditItem extends Component {
constructor(props) {
super(props);
this.state = {items: ''};
this.addItemService = new ItemService();
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
componentDidMount(){
axios.get('http://localhost:3005/items/edit/'+this.props.match.params.id)
.then(response => {
this.setState({ items: response.data });
})
.catch(function (error) {
console.log(error); …Run Code Online (Sandbox Code Playgroud) 正如标题所说,我试图从子组件调用放置在父组件中的方法 (componentDidMount) - 我的应用程序中有以下组件结构:
export default class Today extends Component {
constructor(props) {
super(props);
this.state = {
stats: [],
loading: true
};
}
componentDidMount() {
axios.get(api_url)
.then((res) => {
console.log('res.data');
this.setState({
stats: res.data,
loading: false
});
})
}
render() {
return (
<Stats loading={this.state.loading} stats={this.state.stats} />
);
}
}
Run Code Online (Sandbox Code Playgroud)
和
export default class Stats extends Component {
constructor(props) {
super(props);
}
onRefresh() {
alert('X');
// here I need to refresh the data in 'this.props.stats'
// and re-display it (fresh data) …Run Code Online (Sandbox Code Playgroud) 我从 JSON 加载字典数据,如下所示:
list_of_people = json.load(open('list_of_people.json'))
Run Code Online (Sandbox Code Playgroud)
我想从此 JSON 中选择前 5 个值项。我尝试这样做:
print(data.values()[0:5])
Run Code Online (Sandbox Code Playgroud)
然而,这导致了
TypeError: 'dict_values' object is not subscriptable
Run Code Online (Sandbox Code Playgroud)
我该如何列出呢?