我想問你一些關於React.js的問題。現在我正在做一些React.js練習,看來我犯了一些錯誤。它應該保存,刪除和編輯按鈕,textarea。當你點擊編輯按鈕時,textarea出現。當你點擊保存按鈕時,所有的東西都會返回到默認狀態。反應js:多個孩子的評論
但電腦顯示爲空屏幕。
這裏是我的代碼:
<html>
<head>
<script src = "react-master/../js/react.js"></script>
<script src = "react-master/../js/react-dom.js"></script>
<script src = "js/browser.js"></script>
</head>
<body>
<div id = "example"></div>
<script type = "text/babel">
var Comment = React.createClass({
getInitialState: function(){
return {editing: false}
},
edit: function(){
this.setState({editing: true});
},
remove: function(){
console.log("Removing comments");
},
save: function(){
var val = this.refs.newText.value;
console.log (val);
this.setState({editing: false});
},
renderNormal: function(){
return(
<div className = "comment-container">
<div className = "comment-text">{this.props.children}</div>
<button onClick = {this.edit}>Edit</button>
<button onClick = {this.remove}>Remove</button>
</div>
);
},
renderForm: function(){
return(
<div className = "comment-container">
<textarea ref ="newText" defaultValue = {this.props.children}></textarea>
<button onClick = {this.save}>Save</button>
</div>
);
},
render: function(){
if (this.state.editing){
return this.renderForm();
}else{
return this.renderNormal();
}
}
});
var Board = React.createClass({
getInitialScale: function(){
return (
comments: ["Ira", "Nata", "Nina"]
)
},
render: function(){
return (
<div className = "board">{
this.state.comments.map(function(text, i){
return (<Comment key = {i}>{text}</Comment>);
})
}
</div>
);
}
});
ReactDOM.render(<Board />, document.getElementById("example"));
</script>
</body>
</html>
我該怎麼辦錯了嗎? 問候函