Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.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 如何获得承诺的价值并将其用于选择器_Javascript_Reactjs - Fatal编程技术网

Javascript 如何获得承诺的价值并将其用于选择器

Javascript 如何获得承诺的价值并将其用于选择器,javascript,reactjs,Javascript,Reactjs,我尝试为视频通话应用程序选择媒体设备。我想创建选择器,它包含3个选择器,一个用于麦克风,第二个用于视频,第三个用于扬声器(每个选择器都有自己的选择)。我试图用这种方式来做,但smth是错误的,因为选择器是空的,如果我控制台deviceType的结果,控制台输出承诺{} 如果你知道其他方法,请写 import Select from 'react-select'; import './SettingButton.css'; import videoon from './videoon.png';

我尝试为视频通话应用程序选择媒体设备。我想创建选择器,它包含3个选择器,一个用于麦克风,第二个用于视频,第三个用于扬声器(每个选择器都有自己的选择)。我试图用这种方式来做,但smth是错误的,因为选择器是空的,如果我控制台deviceType的结果,控制台输出承诺{} 如果你知道其他方法,请写

import Select from 'react-select';
import './SettingButton.css';
import videoon from './videoon.png';
import micon from './micon.png';
import speaker from './speaker.png';


let deviceDetected = (navigator.mediaDevices.enumerateDevices() 
.then((devices) => {
   return (devices.map((device) => 
    (device.kind + ": " + device.label)));
})
.catch(function(err) {
  console.log(err.name + ": " + err.message);
}));


 const deviceType = async()=> {
   const a = await deviceDetected;
   console.log (a)
 }


export default function SettingButton(props) {
  function handleSubmit(event) {
    event.preventDefault();
  } 
  
    return  (props.onClickDisplay ? (
      <div className="settingButton">
        <form onSubmit={handleSubmit} >
  
        <div className="iconStyle">
          <img src = {micon} alt='microphone' height='30px' width ='30px' className='imgStyle'/>
         <div className="textStyle">
         <Select option={deviceType()}/>
         </div>
         </div>
  
         <div className="iconStyle">
        <img src = {videoon} alt='video' height='30px' width ='30px' className='imgStyle'/>
          <div className="textStyle">
          <Select option={deviceType()}/>
          </div>
          </div>
          
         <div className="iconStyle">
         <img src = {speaker} alt='speaker' height='30px' width ='30px' className='imgStyle'/>
         <div className="textStyle">
         <Select option={deviceType()}/>
         </div>
         </div>
        </form>
      </div>
    ) : null)
}
从“反应选择”导入选择;
导入“./SettingButton.css”;
从“./videoon.png”导入videoon;
从“./micon.png”导入micon;
从“/speaker.png”导入扬声器;
让deviceDetected=(navigator.mediaDevices.enumerateDevices()
。然后((设备)=>{
返回(devices.map)((设备)=>
(device.kind+“:“+device.label));
})
.catch(函数(err){
console.log(err.name+“:”+err.message);
}));
const deviceType=async()=>{
常数a=等待设备检测到;
console.log(a)
}
导出默认功能设置按钮(道具){
函数handleSubmit(事件){
event.preventDefault();
} 
返回(props.onClickDisplay(
):null)
}

等待承诺。。。 试试这个来做出承诺

let deviceDetected=()=>{
返回新承诺((解决、拒绝)=>{
navigator.mediaDevices.enumerateDevices()
。然后((设备)=>{
让res=(devices.map)((device)=>
(device.kind+“:“+device.label));
解决(res)
})
.catch(函数(err){
拒绝(错误)
console.log(err.name+“:”+err.message);
}));
})
}

不工作,我的问题在于您的代码,`const a=wait deviceDetected;`,a将是未定义的