Показать диалог в React - Material UI - PullRequest
0 голосов
/ 27 мая 2018

Я изучаю ReactJS.Я хотел бы отобразить диалог, когда кто-то нажимает на значок.

Вот код:

import React, { Component } from 'react';
import { GridList, GridTile } from 'material-ui/GridList';
import FlatButton from 'material-ui/FlatButton';
import Info from 'material-ui/svg-icons/action/info';
import { fullWhite } from 'material-ui/styles/colors';
import Dialog from 'material-ui/Dialog';
import RaisedButton from 'material-ui/RaisedButton';

(... class stuff, handleClose, handleOpen etc.)

  showDialoga() {
    const actions = [
      <FlatButton
        label="Cancel"
        primary
        onClick={this.handleClose}
      />,
      <FlatButton
        label="Submit"
        primary
        keyboardFocused
        onClick={this.handleClose}
      />,
    ];
    return (
      <div>
        <RaisedButton label="Dialog" onClick={this.handleOpen} />
        <Dialog
          title="Dialog With Actions"
          actions={actions}
          modal={false}
          open={this.state.open}
          onRequestClose={this.handleClose}
        >
          The actions in this window were passed in as an array of React objects.
        </Dialog>
      </div>
    );
  }
  render() {
    console.log(this.props);
    return (
      <div style={styles.root}>
        <GridList
          cellHeight={180}
          style={styles.gridList}
          padding={10}
        >
          {this.props.movieData.map(tile => (
            <GridTile
              key={tile.original_image}
              title={tile.title}
              actionIcon={<FlatButton
                icon={<Info color={fullWhite} />}
                style={style}
                onClick={() => this.showDialoga()}
              />}
            >
              <img src={tile.original_image} />
            </GridTile>
          ))}
        </GridList>
      </div>
    );
  }
}

Я могу передать другую функцию, такую ​​как () => console.log ('I clicked'), в onClick, хотя я не могупередать это showDialoga ().

Есть идеи, в чем проблема?

1 Ответ

0 голосов
/ 28 мая 2018

Я не верю, что именно так вы должны использовать диалоговое окно.

Вместо того, чтобы передавать возврат компонента React по щелчку, попробуйте установить открытое диалоговое состояние в состояние true / false.Также не забудьте привязать this к уровню класса, если вы используете функции для рендеринга различных компонентов, имеющих прослушиватели событий.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...