【问题标题】:Passing a variable to `renderMenuItemChildren` in react typeahead bootstrap在反应预输入引导程序中将变量传递给`renderMenuItemChildren`
【发布时间】:2019-09-02 10:18:28
【问题描述】:

它从App 组件将变量item 传递给Todo 组件。从Todo 组件传递到SearchResult 组件。但是,`SearchResult '组件没有显示出来。

在这里演示:https://stackblitz.com/edit/react-e2zqvd

import {Typeahead} from 'react-bootstrap-typeahead';

class App extends Component {
  constructor() {
    super();
    this.state = {
      name: [{id:1, name: 'mario'}, {id:2, name: 'paul'}],
      item: 'flower'
    };
  }

  render() {
    return (
      <div>
        <Todo
          item = {this.state.item}
          name = {this.state.name}
        />
      </div>
    );
  }
}

class Todo  extends Component {
  constructor(props){
    super(props);

  }

  render () {
    return (
      <div>
          <Typeahead
            id={'example4'}
            labelKey= 'name'
            multiple
            options={this.props.name}
            onChange={this.handleSelectPeopleToCalendar}
            ref={(ref) => this._typeahead = ref}
            renderMenuItemChildren={(option, props) => (
              <SearchResult
                key={option.id} 
                user={option} 
                item={props.item}
              />
            )}
          />
      </div>
    )
  } 
}

const SearchResult = ({user, item}) => (
    <div>
        <p>{item}</p>
        <span>{user.name}</span>
  </div>
);

【问题讨论】:

    标签: javascript reactjs typeahead.js bootstrap-typeahead


    【解决方案1】:

    试试

    <SearchResult
                key={option.id} 
                user={option} 
                item={this.props.item}
              />
    

    你需要开始输入一些东西才能看到这个组件,输入没有边框,没有背景

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-27
      • 2014-01-05
      • 1970-01-01
      • 2020-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-14
      相关资源
      最近更新 更多