Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.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 将二维excel表格转到筛选下拉列表_Javascript_Reactjs_Sorting_Multidimensional Array_Dropdown - Fatal编程技术网

Javascript 将二维excel表格转到筛选下拉列表

Javascript 将二维excel表格转到筛选下拉列表,javascript,reactjs,sorting,multidimensional-array,dropdown,Javascript,Reactjs,Sorting,Multidimensional Array,Dropdown,你能帮我弄清楚如何使用reactjs将下表转换为过滤下拉列表吗。 我需要按年龄(假设用户33岁)过滤结果,并向他显示其年龄组的可用选项(覆盖资本和与之相关的每月保费),然后捕获所选数据 以下是我迄今为止所取得的成就: 1-将Excel表格转换为CSV,然后使用此网站将其更改为JSON数组。 以下是结果的一个片段: [["111.000 €","25 €","27 €","28 €","31 €",

你能帮我弄清楚如何使用reactjs将下表转换为过滤下拉列表吗。 我需要按年龄(假设用户33岁)过滤结果,并向他显示其年龄组的可用选项(覆盖资本和与之相关的每月保费),然后捕获所选数据

以下是我迄今为止所取得的成就:

1-将Excel表格转换为CSV,然后使用此网站将其更改为JSON数组。 以下是结果的一个片段:

[["111.000 €","25 €","27 €","28 €","31 €","34 €"  ],["138.000 €","32 €","33€","35€","39 €","42 €"  ].... ]
2-从出生日期开始计算年龄,然后连接一个函数以识别用户所属的类别。注意,我称之为索引的是列表项的索引 例如:[“111.000欧元”,“25欧元”,“27欧元”,“28欧元”,“31欧元”,“34欧元]]列表从0,1,2开始。。。 对应于excel工作表上的列

getIndex = (age) => {
    let index = null;
    if (age < 25 ) {
        index = 1
    }
    if (age < 30 && age > 24) {
        index = 2
    }
    if (age < 40 && age > 29) {
        index = 3
    }
    if (age < 45 && age > 39) {
        index = 4
    }
    if (age > 45) {
        index = 5
    }
    this.setState({
        age_index : index
    })
};
由于某种原因,我遇到了一个小问题,状态值只显示最后一项(好像列表没有填充)

有什么想法吗

在我第二次阅读时,我意识到你想要归档的内容。
这是我的解决方案。
这就是环境

导入“/styles.css”; 从“react”导入{Component}; const insuranceTarifs=[ ["111.000 €", "25 €", "27 €", "28 €", "31 €", "34 €"], ["138.000 €", "32 €", "33€", "35€", "39 €", "42 €"], ["238.000 €", "37 €", "39€", "41€", "43 €", "46 €"] ]; 警察人员=[ {id:1,姓名:“Igor”,年龄:11}, {身份证号码:2,姓名:“帖木儿”,年龄:22}, {身份证号码:3,姓名:“迪尔肖德”,年龄:35}, {id:4,姓名:“Uktam”,年龄:43}, {id:5,姓名:“Zarnigor”,年龄:56} ]; 导出默认类应用程序扩展组件{ 状态={ 人寿保险:[] }; handleOnAgeMatch=(计算)=>{ 如果( !this.state.life\u insurance.find( (element)=>element.id==calculation.id ) ) { 这是我的国家({ 人寿保险:[计算,…此。状态。人寿保险] }); } }; render(){ constageElements=persons.map((person)=>(
  • )); const pricePickers=this.state.life\u insurance.map((列表)=>( )); 返回(
      {ageElements}
      {pricePickers}
    ); } } 常量价格选择器=({userPricingList})=>{ const options=userPricingList.customPricingList.map((项)=>( {item.premium} )); 返回(
  • {options}
  • ); }; const Person=({Person,onAgeMatchHandler})=>{ 设index=null; const{age,id,name}=个人; 如果(年龄<25岁){ 指数=1; } 如果(年龄<30岁和年龄>24岁){ 指数=2; } 如果(年龄<40岁和年龄>29岁){ 指数=3; } 如果(年龄<45岁和年龄>39岁){ 指数=4; } 如果(年龄>45岁){ 指数=5; } 常量userPricingList=[]; 保险费率(tarif)=>{ 常数数据={ 大写:塔里夫[0], 保费:tarif[指数] }; userPricingList.push(数据); }); onAgeMatchHandler({id,customPricingList:userPricingList}); 返回( {name}{age}y.o。 ); };
    以下是基于@FarrukhNormuradov Help更新的函数

    createNewArrayLife = (listitem) => {
        const userPricingList = [];
        if (this.state.age_index) {
           listitem.forEach((item) => {
               const data = {
                    capital: item[0],
                    premium: item[this.state.age_index]
               };
               userPricingList.push(data);
           });
        }
        this.setState({
            life_insurance: userPricingList
        });
    };
    

    你好您能展示一下您已经尝试过的吗?@FarrukhNormuradov我已经将表转换为JSON数组,然后我计算年龄,然后使用带有条件语句的函数来确定用户属于哪个类别,然后根据年龄条件匹配分配索引。接下来,我使用foreach创建一个新数组,其中只包含与年龄匹配的参数。然后把它插入下拉列表,我离你越来越近了吗?太棒了,你为什么不把你当前的解决方案放在这里,这样其他人就可以用它来定位缺失的部分?@FarrukhNormuradov我发布了一些代码。你能看一下并告诉我我这里缺失了什么吗?你有机会尝试我的解决方案吗?谢谢你的帮助。你的答案很好,尽管它与我的100%设置不匹配,因为我使用的设置有点复杂。你对forEach的处理是完美的。我用工作函数更新了我的问题。非常感谢你的帮助。你是最棒的
    createNewArrayLife = (listitem) => {
        const userPricingList = [];
        if (this.state.age_index) {
           listitem.forEach((item) => {
               const data = {
                    capital: item[0],
                    premium: item[this.state.age_index]
               };
               userPricingList.push(data);
           });
        }
        this.setState({
            life_insurance: userPricingList
        });
    };