3
关注
1665
浏览

传数据从小孩到在母体阵营节目类型错误

为什么被折叠? 0 个回复被折叠
JFENG_G 未验证用户 用户来自于: 广东省
2020-09-17 10:14

你不要有你的地图功能return语句..请添加回报,也将努力

Yannyezixin 未验证用户 用户来自于: 广东省
2020-09-16 11:31

你没有从.map返回任何东西。

它改成这样:

const listitem = choices.map((name, index) => { 
     return(this.increaseCount} key={index} option={name} />); 

注意,我改变的map匿名函数到arrow function处理的this上下文中词汇的方式。

从您的代码笔链路上运行代码:

class Header extends React.Component { 
 
    render() { 
 
    return (
 
     <div className="col-md-8 col-sm-8 col-xs-8"> 
 
     <p className="title-p"> 
 
      <span className="red-text">Bspan> 
 
      <span className="black-text">ulowsspan>{" "} 
 
      <span className="green-text">Wortshatztestspan> 
 
     p> 
 
     div> 
 
    ); 
 
    } 
 
} 
 

 
class Hicon extends React.Component { 
 
    render() { 
 
    return (
 
     <div className="col-md-4 col-sm-4 col-xs-4 icon-image-div"> 
 
     <img className="icon-image" src="src/img/WT_icon5.png" alt="icon" /> 
 
     div> 
 
    ); 
 
    } 
 
} 
 

 
class Question extends React.Component { 
 
    render() { 
 
    return (
 
     <div className="col-md-12 text-center"> 
 
     <h3 className="question-type">Welche beiden Worter passen gut zu:h3> 
 
     <h1 className="question">Gegensatzh1> 
 
     div> 
 
    ); 
 
    } 
 
} 
 

 
class Instruction extends React.Component { 
 
    render() { 
 
    return (
 
     <div className="col-md-12"> 
 
     <h4 className="attention-text"> 
 
      Wählen Sie Ihre zwei. [attention German Umlaut = auml] 
 
     h4> 
 
     div> 
 
    ); 
 
    } 
 
} 
 

 
class Choice extends React.Component { 
 
    constructor(props) { 
 
    super(props); 
 
    this.state = { isToggleOn: true, selectCount: 0 }; 
 
    this.handleClick = this.handleClick.bind(this); 
 
    } 
 

 
    handleClick() { 
 
    this.setState(prevState => ({ 
 
     isToggleOn: !prevState.isToggleOn 
 
    })); 
 
    console.log(this.state.isToggleOn); 
 
    this.props.onIncreaseCount(); 
 
    } 
 

 
    render() { 
 
    let bgColor = this.state.isToggleOn ? "white" : "green"; 
 
    return (
 
     <div className="col-md-6 text-center btn-div"> 
 
     <a 
 
      style={{ backgroundColor: bgColor }} 
 
      onClick={this.handleClick} 
 
      type="button" 
 
      className="btn" 
 
      href="#" 
 
     > 
 
      {this.props.option} 
 
     a> 
 
     div> 
 
    ); 
 
    } 
 
} 
 

 
class Choices extends React.Component { 
 
    constructor(props) { 
 
    super(props); 
 
    this.state = { 
 
     count: 0, 
 
     choices: [ 
 
     { option: "Krass" }, 
 
     { option: "Einfach" }, 
 
     { option: "Dazu" }, 
 
     { option: "Dafur" } 
 
     ] 
 
    }; 
 
    this.increaseCount = this.increaseCount.bind(this); 
 
    } 
 

 
    increaseCount() { 
 
    this.setState(prevState => ({ 
 
     count: prevState.count + 1 
 
    })); 
 
    if (this.state.count == 2) { 
 
     console.log("kam sarse"); 
 
    } 
 
    } 
 

 
    render() { 
 
    var choices = ["krass", "Einfach", "Dazu", "Dafur"]; 
 
    const listitem = choices.map((name, index) => { 
 
     return(<Choice onIncreaseCount={this.increaseCount} key={index} option={name} />); 
 
    }); 
 

 
    return (
 
     <div className="col-md-12 row"> 
 
     <Choice onIncreaseCount={this.increaseCount} option="Krass" /> 
 
     {listitem} 
 
     div> 
 
    ); 
 
    } 
 
} 
 

 
class App extends React.Component { 
 
    render() { 
 
    return (
 
     <div className="container"> 
 
     <div className="row header"> 
 
      <Header /> 
 
      <Hicon /> 
 
     div> 
 
     <div className="row question-div"> 
 
      <Question /> 
 
     div> 
 
     <div className="row instruction-div"> 
 
      <Instruction /> 
 
     div> 
 
     <div className="row choice-div"> 
 
      <Choices /> 
 
     div> 
 
     div> 
 
    ); 
 
    } 
 
} 
 

 
ReactDOM.render(<App />, document.getElementById("root"));
.header{ 
 
     border-bottom: 5px solid black; 
 
     margin-bottom: 20px; 
 
    } 
 
    .title-p{ 
 
     padding-bottom: 0px !important; 
 
     margin-bottom: -10px; 
 
    } 
 
    .red-text{ 
 
     font-size: 60px; 
 
     font-weight: bold; 
 
     color: red; 
 
    } 
 
    .black-text{ 
 
     font-weight: bold; 
 
     font-size: 25px; 
 
    } 
 
    .green-text{ 
 
     font-size: 35px; 
 
     font-weight: 600; 
 
     color: green; 
 
    } 
 
    .icon-image{ 
 
     height: 50px; 
 
     float: right; 
 
    } 
 
    .icon-image-div{ 
 
     padding-top: 25px; 
 
    } 
 
    .question-div{ 
 
     background-color: aliceblue; 
 
     min-height: 20%; 
 
    } 
 
    .instruction-div{ 
 
     background-color: goldenrod; 
 
     margin-top: 20px; 
 
    } 
 
    .choice-div{ 
 
     margin-top: 30px; 
 
    } 
 
    .zero-padding{ 
 
     padding: 0 !important; 
 
     margin: 0 !important; 
 
    } 
 
    .btn-div{ 
 
     margin-top: 15px; 
 
     margin-bottom: 15px; 
 
    } 
 
    .btn{ 
 
     width: 80%; 
 
     font-weight: bold; 
 
     font-size: 30px; 
 
     color: black; 
 
    } 
 
    .btn:hover{ 
 
     background-color: aquamarine; 
 
    } 
 
    .btn:focus{ 
 
     box-shadow: 0 0 0 0 !important; 
 
     /*background-color: green;*/ 
 
     /*color: white;*/ 
 
    }
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js">script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js">script> 
 
<div id="root">div>

关于作者

问题动态

发布时间
2020-09-15 15:51
更新时间
2022-09-15 15:51
关注人数
3 人关注
个人工作笔记 Powered BY WeCenter V4.1.0 © 2024 粤ICP备2020123311号