Asp.net mvc React.NET uncaught TypeError:undefined不是函数
我正在努力学习ReactJs并找到React.NET 遵循作者的教程,唯一的变化是MVC5应用程序而不是MVC4 以下是jsx:Asp.net mvc React.NET uncaught TypeError:undefined不是函数,asp.net-mvc,reactjs,Asp.net Mvc,Reactjs,我正在努力学习ReactJs并找到React.NET 遵循作者的教程,唯一的变化是MVC5应用程序而不是MVC4 以下是jsx: /** @jsx React.DOM */ var CommentBox = React.createClass({ render: function() { return ( <div className="commentBox"> <h1>Comments</h1> <
/** @jsx React.DOM */
var CommentBox = React.createClass({
render: function() {
return (
<div className="commentBox">
<h1>Comments</h1>
<CommentList data={this.props.data} />
<CommentForm />
</div>
);
}
});
React.renderComponent(
<CommentBox data={data} />,
document.getElementById('content')
);
var CommentList = React.createClass({
render: function() {
var commentNodes = this.props.data.map(function (comment) {
return <Comment author={comment.Author}>{comment.Text}</Comment>;
});
return (
<div className="commentList">
{commentNodes}
</div>
);
}
});
var CommentForm = React.createClass({
render: function() {
return (
<div className="commentForm">
Hello, world! I am a CommentForm.
</div>
);
}
});
var data = [
{ Author: "Daniel Lo Nigro", Text: "Hello ReactJS.NET World!" },
{ Author: "Pete Hunt", Text: "This is one comment" },
{ Author: "Jordan Walke", Text: "This is *another* comment" }
];
/**@jsx React.DOM*/
var CommentBox=React.createClass({
render:function(){
返回(
评论
);
}
});
React.renderComponent(
,
document.getElementById('content')
);
var CommentList=React.createClass({
render:function(){
var commentNodes=this.props.data.map(函数(注释){
返回{comment.Text};
});
返回(
{commentNodes}
);
}
});
var CommentForm=React.createClass({
render:function(){
返回(
你好,世界!我是一个评论人。
);
}
});
风险值数据=[
{作者:“Daniel Lo Nigro”,文字:“Hello ReactJS.NET World!”},
{作者:“皮特·亨特”,正文:“这是一条评论”},
{作者:“Jordan Walke”,正文:“这是另一条评论”}
];
它给出了以下错误:
未捕获类型错误:未定义不是函数
关于这件事有什么线索吗
问候。代码段中有三个步骤 首先,定义
注释框
:
var CommentBox = React.createClass...
其次,呈现CommentBox
和CommentList
:
React.renderComponent...
var CommentList = React.createClass...
第三,定义注释列表
:
React.renderComponent...
var CommentList = React.createClass...
因此,问题在于
CommentList
是在定义CommentList
之前呈现的。如果最后两个步骤被切换,那么它就可以正常工作。CommentList
类在呈现之前需要定义。CommentForm也在错误的位置定义-需要在引用之前定义它。React教程的方法是错误的:
Javascript中类的正确定义顺序为:
var Comment = React.createClass
...
var CommentList = React.createClass
...
var CommentForm = React.createClass
...
var CommentBox = React.createClass
...
在学习本教程时,我发现在jsx脚本顶部声明var data=[…]解决了这个问题。因此,引擎似乎没有正确地提升变量?查看教程,应该是
?教程的作者忘记添加的另一件事是:在html文件中,而不是您需要的(取决于您将tutorial.js放在何处)