簡體   English   中英

在React TypeAhead Bootstrap中將變量傳遞給`renderMenuItemChildren`

[英]Passing a variable to `renderMenuItemChildren` in react typeahead bootstrap

它從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>
);

嘗試

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

並且您需要開始輸入一些內容以查看此組件,其中的輸入無邊框且沒有背景

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM