我使用ReactJS.Net和ASP.NET 5创建了一个小型应用程序。
@using System.Threading.Tasks
@using React.AspNet
@model Models.DashboardViewModel
@Html.React("MessageBoard", new
{
recentPosts = Model.RecentPosts
})messageBoard.jsx
"use strict";
var MessageBoard = React.createClass({
render: function(){
return (<table className="table forum table-striped">
<thead>
<tr>
<th className="cell-stat"></th>
<th>Topic</th>
<th className="cell-stat text-center hidden-xs hidden-sm">Replies</th>
<th className="cell-stat-2x hidden-xs hidden-sm">Last Post</th>
</tr>
</thead>
<tbody>
{this.props.recentPosts.map(function(boardPost){
return <BoardPostRow post={boardPost}/>;
}, this)}
</tbody>
</table>)
}
});一切都很好。问题是,当我转到源代码时,没有.js文件,所以我无法进行调试。对于一些简单的只读元素来说,这可能是可以的。但是现在我想呈现一些包含状态的交互式元素,这是一个用来创建一个新的Post到“留言板”的表单。下面是同一个*.cshtml文件中的代码。
<div id="newPost"></div>
@section scripts
{
<script src="@Url.Content("~/scripts/Components/Board/boardPostForm.jsx")"></script>
<script src="@Url.Content("~/scripts/Components/Common/textInput.jsx")"></script>
<script>React.render(BoardPostForm({}), document.getElementById("newPost"))</script>
@Html.ReactInitJavaScript()
} 我在控制台中遇到的错误是:
Uncaught SyntaxError: Unexpected token <
textInput.jsx:19 Uncaught SyntaxError: Unexpected token <
(index):69 Uncaught ReferenceError: BoardPostForm is not defined(anonymous function) @ (index):69
(index):70 [.NET] Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of MessageBoard. See http://fb.me/react-warning-keys for more information.
(index):71 [.NET] Warning: Unknown DOM property class. Did you mean className?
(index):71 Uncaught ReferenceError: MessageBoard is not defined试图读取.jsx似乎是一个错误,因为当我单击该错误时,它会带我到呈现函数。我在这里错过了什么?也许我需要将jsx>js转换作为构建过程的一部分(我使用的是Gulp),而不是依赖ReactJS.NET?
发布于 2015-09-14 03:53:29
如果你在浏览器中点击/scripts/Components/Board/boardPostForm.jsx会发生什么?它应该显示已编译的JSX,并且在文件的顶部有一些ReactJS.NET信息。如果没有,请确保在您的*.jsx中配置了Web.config处理程序。它应该是这样的:
<add name="ReactJsx" verb="GET" path="*.jsx" type="React.Web.JsxHandlerFactory, React.Web" preCondition="integratedMode" />我在这里错过了什么?也许我需要将jsx>js转换作为构建过程的一部分(我使用的是Gulp),而不是依赖ReactJS.NET?
如果你愿意的话,你可以用杯,你自己决定。这里有一个示例,它使用Webpack进行捆绑,使用ReactJS.NET进行服务器端呈现:https://github.com/reactjs/React.NET/tree/master/src/React.Sample.Webpack。
https://stackoverflow.com/questions/32556594
复制相似问题