小编use*_*090的帖子

ReactJS - 警告:组件正在更改要控制的文本类型的不受控制的输入

我试图摆脱这个错误消息,但仍然没有成功.

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)

javascript reactjs

6
推荐指数
1
解决办法
6883
查看次数

ReactJS - 如何从子组件调用父方法?

正如标题所说,我试图从子组件调用放置在父组件中的方法 (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)

javascript reactjs react-native

1
推荐指数
1
解决办法
5220
查看次数

Python 3 - 如何列出字典中的前 5 个值?

我从 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)

我该如何列出呢?

python dictionary python-3.x

1
推荐指数
1
解决办法
2813
查看次数