일부 텍스트에 버튼 클릭 이벤트를 캡처하거나 경고를 받기 위해 간단한 작업을하고 있습니다. ReactJS JSX 코드는 아래에 붙여 넣습니다.MVC-ReactJS 버튼 onclick 이벤트가 실행되지 않습니다.
var SearchBar = React.createClass({
getInitialState: function() {
return {message: "test"};
},
test1: function(e) {
alert('hi');
this.setState({message: "New Message"});
},
render: function() {
var self = this;
return (
<div>
<button onClick={self.test1}>Change Message</button>
{this.state.message}
</div>
);
},
}); 클릭 이벤트에 this.state.message
값을 변경
@Html.React("SearchBar", new{ })
버튼은 HTML 페이지에 렌더링하지만,없는 얻을 : 같은
내가 MVC의 cshtml에 SearchBar
구성 요소 위에 사용합니다. 어디서 실수합니까?
이 방법도 사용했습니다. 그러나 그것은 작동하지 않습니다. – NeoAsh
https://jsfiddle.net/69z2wepo/53132/ 제게 잘 작동하려면 – ximet
예, 저에게는 맞지만 MVC 및 reactJS.net과 함께 사용할 때는 작동하지 않습니다. – NeoAsh