Fix: Add New File Language Api Wrong6

This commit is contained in:
sylor_huang@126.com 2020-08-13 11:56:39 +08:00
parent f1614a4b62
commit 85d924db70
1 changed files with 16 additions and 15 deletions

View File

@ -1,3 +1,5 @@
import React , { useState , useEffect } from 'react';
import { Select } from 'antd';
import axios from 'axios';
@ -57,28 +59,27 @@ const LANGUAGE = [
export default (({ language , select_language })=>{
const [ languages , setLanguage ] = useState(undefined);
useEffect(()=>{
const url = '/dev_ops/languages.json';
axios.get(url).then(result=>{
if(result){
setLanguage(result.data);
}
}).catch(error=>{
console.log(error);
})
},[])
// useEffect(()=>{
// const url = '/dev_ops/languages.json';
// axios.get(url).then(result=>{
// if(result){
// setLanguage(result.data);
// }
// }).catch(error=>{
// console.log(error);
// })
// },[])
function changelanguage(value){
let array = value ? languages.filter(item=>item.name === value) :undefined;
select_language(value,array && array[0]);
// let array = value ? languages.filter(item=>item.name === value) :undefined;
select_language(value);
}
return(
<Select showSearch={true} placeholder={"请选择文本语言"} style={{ width: 200 }} value={language} onChange={changelanguage}>
<Option value={undefined}>请选择文本语言</Option>
{languages && languages.map((item, key) => {
return <Option value={item.name}>{item.name}</Option>;
{LANGUAGE && LANGUAGE.map((item, key) => {
return <Option value={item}>{item}</Option>;
})}
</Select>
)