Arrays React为什么这个简单的数组映射函数不返回任何内容?
我有一个React组件为数组中的项目创建项目符号列表(称为activePath)。阵列通过console.log正确报告,格式如下:Arrays React为什么这个简单的数组映射函数不返回任何内容?,arrays,reactjs,Arrays,Reactjs,我有一个React组件为数组中的项目创建项目符号列表(称为activePath)。阵列通过console.log正确报告,格式如下: {设备id:“nlab5320a”,端口id:“XGigabitEthernet0/0/3”} 阵列中有六个。我做了一个Array.isArray只是为了确认这是一个真实的数组,它是。我正在尝试映射此数组并输出一个项目符号列表,其中包含以下内容: activePath.map((项目,i)=>( {item.device\u id} )); 这是整个组件 导出
{设备id:“nlab5320a”,端口id:“XGigabitEthernet0/0/3”}
阵列中有六个。我做了一个Array.isArray只是为了确认这是一个真实的数组,它是。我正在尝试映射此数组并输出一个项目符号列表,其中包含以下内容:
activePath.map((项目,i)=>(
{item.device\u id}
));
这是整个组件
导出默认类服务信息扩展React.Component{
render(){
const{activePath}=this.props;
const runTable=activePath.map((项,i)=>(
{item.device\u id}
));
返回(
{runTable}
);
}
}
ServicesInfo是子组件。这是家长
export default class InfoHolder extends React.Component {
constructor(props) {
super(props) {
}
render() {
return(
<div>
<p>Here is a listing of the nodes:</p>
<ServicesInfo />
</div>
)
}
导出默认类InfoHolder.Component{
建造师(道具){
超级(道具){
}
render(){
返回(
以下是节点列表:
)
}
一个没有文本的项目符号正在返回。我已经在这个项目中工作了16个小时了,我想我只是错过了一些简单的东西。请帮助!在
InfoHolder
中,你没有通过activePath
作为ServicesInfo
组件的道具。你必须像这样通过activePath
:
在组件中传递数组。 同时添加
构造函数(道具){
超级(道具){}
从其他组件获取道具
export default class InfoHolder extends React.Component {
constructor(props) {
super(props) {
this.state={
objectArray =[{device_id: "nlab5320a", port_id: "XGigabitEthernet0/0/3"}]
}
}
render() {
return(
<div>
<p>Here is a listing of the nodes:</p>
<ServicesInfo activePath={this.state.object} />
</div>
)
}
export default class ServicesInfo extends React.Component {
constructor(props) {
super(props) {
}
render() {
const { activePath } = this.props;
const runTable = activePath.map((item, i) => (
<li key={i}>{item.device_id}</li>
));
return (
<div>
<ul>{runTable}</ul>
</div>
);
}
}
导出默认类InfoHolder.Component{
建造师(道具){
超级(道具){
这个州={
objectArray=[{device_id:“nlab5320a”,port_id:“XGigabitEthernet0/0/3”}]
}
}
render(){
返回(
以下是节点列表:
)
}
导出默认类服务信息扩展React.Component{
建造师(道具){
超级(道具){
}
render(){
const{activePath}=this.props;
const runTable=activePath.map((项,i)=>(
{item.device\u id}
));
返回(
{runTable}
);
}
}
此代码是您在渲染函数内部或单独的函数组件内部编写的。请包含您的整个组件好吗?您问题中当前的代码不足以说明可能的错误。我正在渲染函数中运行它,并使用const runTable=activePath.map((item,I)=>props
传递给ServicesInfo
。因此this.props.activePath
在ServicesInfo
组件中始终是未定义的。