我正在尝试使用react-select 组件的异步版本。我的正常版本工作得很好,但是当我添加尝试使用项目文档中的这个异步示例时:
var Select = require('react-select'); 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); }; <Select.Async name="form-field-name" loadOptions={getOptions} />
我在控制台中收到此错误:
警告:React.createElement:类型不应为 null、未定义、布尔值或数字。它应该是一个字符串(对于 DOM 元素)或一个 ReactClass(对于复合组件)。检查
OrderHeaderEdit
.
我一直在尝试将其调试到 React 代码中,但我一生都无法弄清楚发生了什么。
这是我对上面具有异步选择组件的组件的完整组件代码。此控件在 Meteor 1.3 应用程序中运行:
import React from 'react';
import Select from 'react-select';
const OrderHeaderEdit = React.createClass({
getOptions(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);
},
render() {
console.log("OrderHeaderEdit props: ", this.props);
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);
};
return (
<div>
<Select.Async
name="form-field-name"
loadOptions={getOptions}
/>
</div>
);
}
});
export default OrderHeaderEdit;
似乎问题可能出在行中的“.Async”扩展名上Select.Async
,这可能会让 Meteor 感到困惑吗?