我編寫了一個react類,但Chrome在渲染函數中拋出了語法錯誤。渲染函數語法中的ReactJS錯誤
我在這裏附上代碼:
var Chatrooms = React.createClass({
getInitialState: function() {
return {
loaded: false,
pages: undefined,
id: "-1",
};
},
loadPages: function() {
url = "/chat/api/chatroom/" + this.props.course + "/get/?format=json";
request = ajax_json_request(url, "GET", {});
request.done(function(response) {
response = jQuery.parseJSON(response);
oldState = this.state;
oldState['chatrooms']=response;
oldState['loaded']=true;
this.setState(oldState);
}.bind(this));
},
componentDidMount: function() {
if(!this.state.loaded) {
this.loadPages();
}
},
render: function(){
console.log(this.state.chatrooms);
return (
<div></div>
);
}
});
瀏覽器中顯示行<div></div>
誤差爲Uncaught SyntaxError: Unexpected token <
。我在網上檢查了語法,它對我來說很好。
您是否將JSX中的代碼轉換爲常規JavaScript? – magnudae 2015-03-03 12:50:18