即使已定义属性,也无法读取未定义的属性“标头”

时间:2020-09-18 01:38:13

标签: reactjs

所以我遇到了这段代码,想将其与我创建的表结合起来。我应对并粘贴它以使其破裂并理解它。但是我一直遇到这个问题,“无法读取未定义的属性'headers'”。我仍然是新手,但是我已经做过很多次了,我只是s脚为什么会发生这种情况

代码:

const TableDnD = (superclass) => class extends superclass {

constructor() {
    super();
    this.state = this.state || {};
    this.state.columnX = 0;
    this.state.columnY = 0;
    this.state.dragging = false;
}

dragHandle(children) {
    return (
      <span onMouseDown={this._onStartDrag.bind(this)}>
        {children}
      </span>
    )
}

dragContainer(children) {
    const dragColumn = this.state.dragging ? this._renderDragColumn() : null;
    const styles = {
    position: "relative"
    };
    return (
      <div
        onMouseUp={this._endDrag.bind(this)}
        onMouseMove={this._updateStyles.bind(this)}
        onMouseOver={this._isOver.bind(this)}
        onMouseLeave={this._exitWithoutChange.bind(this)}
        style={styles}
        ref={(container) => this.container = container}
      >
        {children}
        {dragColumn}
      </div>
    )
}

   // Bunch of code for drag and drop table
}

class Table extends TableDnD(Component) {

constructor(props) {
    super(props);

    this.state = {
        headers: this.props.headers, // right here the error haapens
        data: this.props.data,
    }
}

// other code
// render the component
render() {
   const headers = this.renderHeaders();
   const data = this.renderRows();
   // And finally, the table must be wrapped in the dragContainer method. That's it!
   return this.dragContainer(
       <table className="table">
           <thead>
               <tr>
                   {headers}
               </tr>
           </thead>
       <tbody>
          {data}
       </tbody>
    </table>
    );
  }
}

export default Table

直接位于“标头:this.props.headers”处,并带有数据。错误:无法读取未定义的属性“标头”。

甚至我声明了header属性。

我想念什么吗?

1 个答案:

答案 0 :(得分:3)

应该是import pygame keylst = input('Enter Keys to use (Left Right Up Down)').lower() # enter> a d w s kLeft, kRight, kUp, kDown = (ord(k) for k in keylst.split()) # ascii codes, split on space #this is where i would have i find out what keys the user want's to use #The k1,k2,k3,k4s def move(rect, vel): keys = pygame.key.get_pressed() if keys[kLeft]: rect.x -= vel if keys[kRight]: rect.x += vel if keys[kUp]: rect.y -= vel if keys[kDown]: rect.y += vel screen= pygame.display.set_mode([500,500]) running = True red = pygame.Rect(225,225,50,50) clock = pygame.time.Clock() while running: screen.fill([255,255,255]) pygame.draw.rect(screen,[255,0,0],red) pygame.display.flip() move(red,1) #ADWS being the keys i want to use to move for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() running = False ,而不是props.headers

下一行this.props.headers会发生同样的事情