2017-03-07 41 views
0

我來自angularjs背景,用2種方式綁定我不必擔心太多,只需聲明一個提交函數,我就可以得到已更改或未更改的值。改變反應形式,但輸入值不可編輯

我現在反應停滯。我的輸入不可編輯。

class HelloWorldComponent extends React.Component { 

    constructor(){ 
    super(); 

    this.handleChange = this.handleChange.bind(this) 
    } 

    render() { 
    const person = {"name":"james"}; 
    return (  
     <input onChange={this.handleChange} type="text" placeholder="name" value={person.name} />  
    ); 
    } 

    handleChange(e){ 

    } 
} 

React.render(
    <HelloWorldComponent />, document.getElementById('react_example') 
); 

http://jsbin.com/huluqifanu/1/edit?js,console,output

而且下一步該怎麼做?我應該首先將api數據設置爲狀態?

回答

1

如果你不想使用Controlled Components那麼你可以使用Uncontrolled Components

具體而言,您可以在input上使用defaultValue道具代替value。至於你的第二個問題,你將不得不更清楚你在問什麼,或者更好的問一個單獨的問題。