2017-11-20 4 views
0

私はreactjsを初めて使用しています。私はそれを使用してプロジェクトを作成しています。複数のコンポーネントを使用しているときに問題があります。ここでは、シナリオ反応に複数の成分を使用する

ページがロードされたときに、両方のコンポーネントは、型の値をロードしgetcpeyearlysvalとgetvnfyearlysvalは私だけthis.setDataMeter1関数を呼び出すCPEコンポーネントを入力するとき、今私が欲しい

setDataMeter1(){ 
    //here i want only type cpe componnet will load 
    } 

<Speedometer type = "cpe" getcpeyearlysval={this.objSpeedometer.getcpeyearlys}/> 
    <Speedometer type = "vnf" getvnfyearlysval={this.objSpeedometer.getvnfyearlys}/> 

に設定されているが、動作するはずですしかし、問題は両方の呼び出しです。

<select value={this.state.selectValue} onChange={this.setDataMeter1}> 

In Speedometer component: 
    renderIcon(key, val) { 
     if(key == 'vnf') { 
     console.log("vnf") 
     } 
     if(key == 'cpe'){ 
     console.log("cpe")// this condition should met 
     } 
    } 
    render() { 
     return (
      this.renderIcon(this.props.type, this.props) 
     ); 
    } 
} 

しかし、私の問題はスピードメーターコンポーネントの両方の条件メッツです。

+0

レンダリングを停止するには、 'vnf'条件が満たされた後に' renderIcon'関数から 'nullを返す '必要があります。 –

+1

これは明らかではありません...もっとコードを表示する必要があります – challenger

答えて

0
renderIcon(props) { 
     if(props.type == 'vnf') { 
     return <Text>hey this is vnf </Text> 
     } 
     if(props.type == 'cpe'){ 
     return <Text>hey this is cpe </Text> 
     } 
    } 
    render() { 
     return (
      this.renderIcon(this.props) 
     ); 
    } 
関連する問題