Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 反应选择,异步选项,不显示任何值 从“React”导入React; 从“反应选择”导入选择; 需要(“../node_modules/react-select/dist/react-select.css”); const getOptions=(输入)=>{ 返回fetch(`/games/uni/autocomplete/${input}`) 。然后((响应)=>{ 返回response.json(); })。然后((json)=>{ console.log(json) 返回{options:json}; }); } var SearchBar=React.createClass({ render:function(){ 返回( ) } }); 导出默认搜索栏;_Javascript_Reactjs_React Select - Fatal编程技术网

Javascript 反应选择,异步选项,不显示任何值 从“React”导入React; 从“反应选择”导入选择; 需要(“../node_modules/react-select/dist/react-select.css”); const getOptions=(输入)=>{ 返回fetch(`/games/uni/autocomplete/${input}`) 。然后((响应)=>{ 返回response.json(); })。然后((json)=>{ console.log(json) 返回{options:json}; }); } var SearchBar=React.createClass({ render:function(){ 返回( ) } }); 导出默认搜索栏;

Javascript 反应选择,异步选项,不显示任何值 从“React”导入React; 从“反应选择”导入选择; 需要(“../node_modules/react-select/dist/react-select.css”); const getOptions=(输入)=>{ 返回fetch(`/games/uni/autocomplete/${input}`) 。然后((响应)=>{ 返回response.json(); })。然后((json)=>{ console.log(json) 返回{options:json}; }); } var SearchBar=React.createClass({ render:function(){ 返回( ) } }); 导出默认搜索栏;,javascript,reactjs,react-select,Javascript,Reactjs,React Select,log(json)类似于:[“EA体育FIFA 16”,“FIFA 16终极团队”] 但是suggeestion值为空 这里是组件异步的状态和特性 以下是官方文件和示例: 我缺少什么?在你的console.log(json)中,你打印出一个包含字符串的数组,它不是一个对象数组 如文档所述,您需要按如下方式格式化数据。在你归还之前 示例 import React from 'react'; import Select from 'react-select'; require("../node_

log(json)类似于:
[“EA体育FIFA 16”,“FIFA 16终极团队”]

但是suggeestion值为空

这里是组件异步的状态和特性

以下是官方文件和示例:

我缺少什么?

在你的console.log(json)中,你打印出一个包含字符串的数组,它不是一个对象数组

如文档所述,您需要按如下方式格式化数据。在你归还之前

示例

import React from 'react';
import Select from 'react-select';
require("../node_modules/react-select/dist/react-select.css");   

const getOptions = (input) => {
      return fetch(`/games/uni/autocomplete/${input}`)
        .then((response) => {
          return response.json();
        }).then((json) => {

      console.log(json)
      return { options: json };
    });
}


var SearchBar = React.createClass({
    render: function() {
       return (

            <Select.Async
              name="form-field-name"
              loadOptions={getOptions} />   
    )
  }
});

export default SearchBar;

同样的问题,我返回了一个对象数组,但仍然得到一个空数组dropdown@AvremelKaminetzky如果json响应不是属性为“value”和“label”的对象数组,那么可以使用valueKey属性指定值,使用labelKey属性指定标签……没错。但我的问题是,我没有显式返回fetch函数。
const json = [
 { value: 'EASPORTFIFA16', label: 'EA SPORTS FIFA 16' },
 { value: 'FIFA16UltimateTeam', label: 'FIFA 16 Ultimate Team' }
]