1
誰でもJavaスクリプトでこのエラーを助けてください。私はReactルーターを使ってページのさまざまなコンポーネントを表示しています。それらのコンポーネントの1つは 'forEach'です。コンソールは "forEach"プロパティで問題を出しています。何が問題ですか ?このjsファイルをメインのhtmlファイルに含めました。Uncaught TypeError:javascript/React-router/Reactで未定義の 'forEach'プロパティを読み取れません
var ProductTable = React.createClass({
render: function() {
var rows = [];
var lastCategory = null;
this.props.products.forEach(function(product) {
if (product.name.indexOf(this.props.filterText) === -1 || (!product.stocked && this.props.inStockOnly)) {
return ;
}
if (product.category !== lastCategory) {
rows.push(React.createElement(ProductCategoryRow, { category: product.category, key: product.category }));
}
rows.push(React.createElement(ProductRow, { product: product, key: product.name }));
lastCategory = product.category;
}.bind(this));
return (
React.createElement("table",null,
React.createElement("thead",null,
React.createElement("tr",null,
React.createElement("th",null,"Name"),
React.createElement("th",null,"Price")
)
),
React.createElement("tbody",null,rows)
)
)
}
});
あなたは 'createClass'とforeach要素を作成する必要はありません配列として必ずあなたの親コンポーネントを通過している製品を作るためにdefaultPropsを使用することができますか?これを確認してください:http://stackoverflow.com/questions/33681136/react-js-foreach-as-a-first-class-component – SrAxi
'this.props.products'は' undefined 'ですので ' forEach'メソッドを呼び出します。 'render()'が呼び出される前に、実際に入力されていることを確認してください。 –
実際に発生したエラーは何ですか? – Zargold