2017-11-20 2 views
0

reactjs에 익숙하며이를 사용하는 프로젝트를 만들고 있습니다. 여러 구성 요소를 사용하는 동안 문제가 있습니다. 다음 페이지가 모두 구성 요소, getcpeyearlysval 유형의 값을로드하고 난 단지 작동합니다 CPE 구성 요소를 입력 this.setDataMeter1 함수를 호출 할 때반응에 여러 구성 요소 사용

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

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

지금 내가 원하는 getvnfyearlysval 설정로드 시나리오

입니다 ,하지만 문제는 두 가지 호출입니다.

<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) 
     ); 
    }