2

我在使用react-bootstrap-typeahead項目中的AsyncTypeahead時出現問題,看起來好像我的onSearch處理程序未被調用。我可以在頁面上看到類型提示,但是當我鍵入它時,handleSearch未被執行,並且我沒有看到任何控制檯日誌記錄。這裏有一個簡單的例子:從react-bootstrap-typeahead包使用AsyncTypeahead問題

import React, {PropTypes, Component} from 'react'; 
 
import AsyncTypeahead from 'react-bootstrap-typeahead'; 
 
class CustomTypeahead extends Component { 
 
    
 
    state = { results: [] } 
 
    
 
    handleSearch(event) { 
 
    console.log("Show me what you got") 
 
    // fetch data here and set state to results in a promise 
 
    // this.setState(results) 
 
    } 
 
    
 
    render() { 
 
    return (
 
     <div> 
 
     <AsyncTypeahead 
 
      onSearch={this.handleSearch.bind(this)} 
 
      options={this.state.results}/> 
 
     </div> 
 
    ) 
 
    } 
 
}

任何建議或見解真的很感激!

+2

這結束了與我使用與該版本的一個問題我正在閱讀的文檔!總是檢查版本.... – daschi

回答

2

通過使用固定:的

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

代替

import AsyncTypeahead from 'react-bootstrap-typeahead'; 

,並更新到版本^ 1.0.0 react-bootstrap-typeahead