Seguendo il tutorial react.js, ho un errore: Uncaught TypeError: Cannot read property 'map' of undefined
.ReactJS non riesce con un errore "Impossibile leggere la 'mappa' di proprietà di undefined`"
Stavo seguendo the tutorial rigoroso ma bloccato a prelevamento dal server part. L'errore appare quando invio feedBox con dati url invece dei dati JSON codificati.
/** @jsx React.DOM */
var converter = new Showdown.converter();
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" }
];
var Comment = React.createClass({
render: function() {
var rawMarkup = converter.makeHtml(this.props.children.toString());
return (
<div className="comment">
<h2 className="commentAuthor">
{this.props.author}
</h2>
<span dangerouslySetInnerHTML={{__html: rawMarkup}} />
</div>
);
}
});
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 CommentBox = React.createClass({
render: function() {
return (
<div className="commentBox">
<h1>Comments</h1>
<CommentList data={this.props.data} />
<CommentForm />
</div>
);
}
});
React.renderComponent(
//<CommentBox data={data}/>, //this works fine
<CommentBox url="/comments" />, //Changing data feet to url produces an error
document.getElementById('content')
);
La richiesta al http://localhost:52581/comments
sta lavorando e restituisce un dato JSON:
[{"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"}]
Tutto il consiglio sarebbe di grande aiuto per me. Grazie.
Sì. Anche in questo problema. Il tutorial aggiunge un commento 'Nota: il codice non funzionerà in questo passaggio.' – unicornherder
@unicornherder dannazione. avrebbero potuto renderlo audace – vumaasha