Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在React中以列表格式输出数组_Javascript_Reactjs_Redux - Fatal编程技术网

Javascript 在React中以列表格式输出数组

Javascript 在React中以列表格式输出数组,javascript,reactjs,redux,Javascript,Reactjs,Redux,我在输出一些数据时遇到了一些困难。数据的格式如下所示: 您可以看到阵列中的每个对象都有一个比赛日键、awayTeam键、主队键和一个结果键。除了matchday键之外,其余的都有一个数组作为值 下面是我的代码 import React, { Component } from 'react'; import { connect } from 'react-redux'; import FixtureList from '../components/league-fixture-list';

我在输出一些数据时遇到了一些困难。数据的格式如下所示:

您可以看到阵列中的每个对象都有一个比赛日键、awayTeam键、主队键和一个结果键。除了matchday键之外,其余的都有一个数组作为值

下面是我的代码

import React, { Component } from 'react';
import { connect } from 'react-redux';

import FixtureList from '../components/league-fixture-list';

class LeagueFixtures extends Component {

  render() {
    return (
      <div>
        <div className="row">
          <div className="col-xs-12">
            <h2>Fixtures</h2>
          </div>
        </div>
        <div className="row">
          {this.props.leagueFixtures.map((fixture, index) => {
            return <FixtureList matchday={fixture.matchday} awayTeam={fixture.awayTeam} homeTeam={fixture.homeTeam} key={index} result={fixture.results}/>
          })}
        </div>
      </div>
    )
  }
}


const mapStateToProps = (state) => ({
  leagueFixtures: state.LeagueFixtures
})

const mapDispatchToProps = (dispatch) => {
  return {
  }
}

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(LeagueFixtures)
import React,{Component}来自'React';
从'react redux'导入{connect};
从“../components/league fixture list”导入FixtureList;
类LeagueFixtures扩展组件{
render(){
返回(
固定设施
{this.props.leagueFixtures.map((fixture,index)=>{
返回
})}
)
}
}
常量mapStateToProps=(状态)=>({
leagueFixtures:state.leagueFixtures
})
const mapDispatchToProps=(调度)=>{
返回{
}
}
导出默认连接(
MapStateTops,
mapDispatchToProps
)(联赛)
我想把每一项都匹配起来例如,awayTeam数组的第一项与homeTeam数组的第一项和result数组的第一项匹配。

这是否可能在React中实现?目前,我的当前代码正在执行以下操作:


谢谢:)

您可以使用索引在每个阵列中通过团队吗

例如:

{
this.props.leagueFixtures.map((fixture,index)=>);
}

如果不知道您的
修复程序列表中有什么内容,就无法回答。但是,我猜您正在创建10个面板(一个
Fixture
component??)。在构造每个
Fixture
/面板时,需要确保调用的是homeTeam和awayTeam数组中的索引值,而不是整个数组

将夹具数据作为文本包含在问题本身中。不要对代码和数据使用截图<代码>从'React'const FixtureList=(props)=>{console.log(props);返回(
  • {props.matchday}
  • {props.awayTeam}
  • );导出默认FixtureList看起来像是
    FixtureList
    是我想象的
    Fixture
    的样子(即一个面板)。在这种情况下,看起来@woolm110的答案是正确的,将索引的home/awayTeam直接传递到
    FixtureList