0
我想使用this component與使用es5的異步選項。我在我的componentDidmount服務調用,它使用一個回調設置學校陣列:反應選擇異步選項,
componentDidMount: function(){
SchoolsDataService.getSchools(
this.setSchoolsState
);
哪個學校列表設置爲狀態數組
setSchoolsState: function(data){
this.setState({schools: data.schools})
},
服務:
getSchools: function (callback) {
var url = 'xxxx';
request
.get(url)
.set('Accept', 'application/json')
.end(function (err, res) {
if (res.ok) {
var data = res.body;
if (data) {
callback(data);
}
}
});
}
如何我可以使用文檔中的示例進行設置嗎?我會在哪裏將這種異步版本的服務調用並生成選項列表?
<Select.Async
name="form-field-name"
value="one"
loadOptions={getOptions}/>
我得到這個錯誤:
var getOptions = function(input, callback) {
setTimeout(function() {
callback(null, {
options: [
{ value: 'one', label: 'One' },
{ value: 'two', label: 'Two' }
],
// CAREFUL! Only set this to true when there are no more options,
// or more specific queries will not be sent to the server.
complete: true
});
}, 500);
};
我的組件使用呈現
未捕獲不變違規:元素類型無效:預期字符串(內置組件)或類/函數(用於複合組件),但得到:未定義。檢查TableModalComponent
的渲染方法。
我有它在我的頁面的頂部:
Select = require('react-select'),