Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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
Reactjs 莫代尔元';不要出现在反应中_Reactjs - Fatal编程技术网

Reactjs 莫代尔元';不要出现在反应中

Reactjs 莫代尔元';不要出现在反应中,reactjs,Reactjs,我使用的是react bootstrap,组件函数中有一个模态,如下所示: // stateless function component function ServiceModal(props) { return ( <Modal> <Modal.Dialog> <Modal.Header> <Modal.Title>{prop

我使用的是react bootstrap,组件函数中有一个模态,如下所示:

// stateless function component
function ServiceModal(props) {
    return (
        <Modal>
            <Modal.Dialog>
                <Modal.Header>
                    <Modal.Title>{props.item.name}</Modal.Title>
                </Modal.Header>

                <Modal.Body>
                    <p>{props.item.id}</p>
                    <p>{props.item.name}</p>
                    <p>{props.item.description}</p>
                </Modal.Body>

                <Modal.Footer>
                    <Button variant="secondary">Close</Button>
                </Modal.Footer>
            </Modal.Dialog>
        </Modal>
    );
}
//无状态函数组件
功能服务模式(道具){
返回(
{props.item.name}
{props.item.id}

{props.item.name}

{props.item.description}

接近 ); }
此模式不显示。内容不显示,甚至覆盖也不显示。下面是我如何调用它来渲染它:

class Service extends Component {

renderServiceModal(service) {
    return (
        <ServiceModal
            item={service}
        />
    );
}

render() {
    return (
      <div className="container content">
          <div className="row">
              <div className="col-6">
                  <form>
                    <div className="form-group">
                        <label htmlFor="nom">Name</label>
                        <input name="name" ref="name" type="text" className="form-control" id="name" placeholder="Name"
                               onChange={(value) => this.onChange(value)} />
                    </div>
                    <div className="row">
                      <div className="col-sm-3">
                          <button onClick={this.postService.bind(this)} type="submit" className="btn btn-primary btn-block">Add</button>
                      </div>
                    </div>
                  </form>
              </div>
              <div className="col-6">
                  <ul className="list-group">
                      {this.state.services.map(service =>
                          <li onClick={() => { this.readOneService(service.id) }} className="list-group-item" key={service.id}>{service.nom}
                                <div className="btn-group btn-group-sm float-right" role="group">
                                    <button type="button" className="btn btn-primary"
                                            onClick={() => this.updateService(service.id)}>Update
                                    </button>
                                    <button type="button" className="btn btn-danger"
                                            onClick={() => this.deleteService(service.id)}>Delete
                                    </button>
                                </div>
                            </li>
                      )}
                  </ul>
              </div>
          </div>
      </div>
    );
}
类服务扩展组件{
renderServiceModal(服务){
返回(
);
}
render(){
返回(
名称
this.onChange(value)}/>
添加
    {this.state.services.map(service=>
  • {this.readOneService(service.id)}className=“list group item”key={service.id}>{service.nom} this.updateService(service.id)}>Update this.deleteService(service.id)}>Delete
  • )}
); }
什么也看不出来。。。有什么帮助吗


编辑:更新了问题,在我的主组件中渲染内部代码

默认情况下,模式是隐藏的:

您需要将
show
属性设置为true:(

完整代码

// stateless function component
function ServiceModal(props) {
    return (
        <Modal show={true}>
            <Modal.Dialog>
                <Modal.Header>
                    <Modal.Title>{props.item.name}</Modal.Title>
                </Modal.Header>

                <Modal.Body>
                    <p>{props.item.id}</p>
                    <p>{props.item.name}</p>
                    <p>{props.item.description}</p>
                </Modal.Body>

                <Modal.Footer>
                    <Button variant="secondary">Close</Button>
                </Modal.Footer>
            </Modal.Dialog>
        </Modal>
    );
}
//无状态函数组件
功能服务模式(道具){
返回(
{props.item.name}
{props.item.id}

{props.item.name}

{props.item.description}

接近 ); }
您必须在渲染内部调用此函数(ServiceModal)。

您能提供更多代码吗?也许
render(){…}
@Tolsee中有什么好的@Tolsee更新,谢谢您的建议!这不是问题所在,但我发现了一些问题,我认为这是因为ServiceModal函数不在渲染中?