2017-12-22 15 views
2

私はreactjsを新しくしていて、ボリュームバーを作成中です。reactjsハンドル変数状態の更新で挿入

setstatehandleclick();にを入力する私のための別の方法があります私は自分の価値と私の状態を更新し、私は私の機能setVolume();

にそれをhandleclick() {};ので、私は更新されたテイクの状態でそれを入力して、挿入したいのですが?

import React from 'react' 
import Slider from 'react-rangeslider' 
import 'react-rangeslider/lib/index.css' 
import './css/Volume.css' 

class VolumeBar extends React.Component 

constructor(props, context) { 
super(props, context) 
this.state = { 
    volume: 0 
} 
} 

handleOnChange = (value) => { 
this.setState({ 
    volume: value 
}) 
} 

handleClick(volume) { 
window.DZ.player.setVolume() 
    } 

render() { 
    let { volume } = this.state 
    console.log(volume); 
return (
    <div className="VolumeBar"> 
    <Slider value={volume} orientation="horizontal" onChange= {this.handleClick} /> 
    </div> 
); 
} 
} 

export default VolumeBar 
+0

あなたは決してあなたの 'handleOnChange'メソッドを呼び出すことはありません。あなたはhandleClick onChangeを呼び出しています。おそらく 'onChange = {this.handleOnChange}'に変更し、 'window.DZ.player.setVolume'呼び出しをあなたの' handleOnChange'関数に移動したいと思うでしょう。 – brub

+0

handleOnChange(){ this.setState({ 音量:値 }) window.DZ.player.setVolume(ボリューム) } setVolume()マイルボリュームに挿入/そしてそれは私が値Iを取得する方法のニーズ必要 –

答えて

0

あなたはそれを試しましたか?

<Slider value={volume} orientation="horizontal" onChange=this.handleOnChange} /> 


handleOnChange = (e) => { 
    this.setState({ 
     volume: e.target.value 
}) 

現在の音量を設定しますか?

0

ありがとうございました。

関連する問題