uncatch TypeError:无法读取 javascript / React-router / React 中未定
Uncaught TypeError: Cannot read property 'forEach' of undefined in javascript / React-router / React
任何人都可以帮助解决java脚本中的此错误吗?我正在使用 React 路由器来显示页面的各种组件。其中一个组件是"forEach"。控制台出现"forEach"属性问题。问题出在哪里?已将此js文件包含在主html文件中。
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)
)
)
}
});
您可以使用 defaultProps 来处理此问题,并确保父组件将产品作为数组传递
getDefaultProps: function() {
return products: []
}
相关文章:
- react router router.HistoryLocation以<noscript>但没有完美的工作
- React Router一直给我一个警告:你不能更改<路由器路由>
- 使用react router/react router redux将特定的redux操作绑定到一个路由
- 组件未使用ReactJS和React Router进行渲染
- React Router,在params之后嵌套路由
- 如何在 React-router 中手动调用 Link
- 我的React应用程序的根文件夹与React Router冲突
- React-router 在添加历史记录后不会渲染组件
- 直接使用 React Router + React + Flux 路由到 URL
- 对不同的路由使用相同的组件与 React Router
- 如何使用React Router在Route Handler上获取参数
- React Router浏览器历史记录适用于本地,而不适用于生产
- 带有嵌套子级的React Router
- 使用React Router进行服务器渲染时如何避免localStorage ReferenceError
- React-Router RouteHandler Undefined
- React Router和React Intl:有没有更好的方法来动态加载翻译's路线
- this.props.history已被弃用(react router)
- React-Redux React-router Store 在 props 中不可用
- 重定向到在 React-router 2 中以编程方式重定向到页面
- uncatch TypeError:无法读取 javascript / React-router / React 中未定