2016-11-07 1 views
2

방금 ​​Android에서 React Native로 최근에 이전했습니다. 그러므로 도움이 필요합니다. 왜 다른 클래스에서 URL_API_SERVER를 호출 할 때 같은 클래스의 변수에 액세스 할 수 없으면 'Undefined/api/v2'가 표시됩니다. 당신이 static 변수를 사용하고 있기 때문에React Native - 동일한 클래스에서 정적 변수에 액세스

class Constant { 
    static BASE_URL = 'https://xxxxx'; 
    static URL_API_SERVER = this.BASE_URL + '/api/v2'; 
    static STATIC_BASEURL = this.BASE_URL + '/static'; 
    static URLSTRING_FAQ = this.STATIC_BASEURL + '/FAQ.html'; 
    static URLSTRING_TOU = this.STATIC_BASEURL + '/TOU.html'; 
} 

export default Constant; 

답변

3

, 당신은 this을 사용할 수 없습니다. 아래의 정적 변수에 액세스 할 수 있습니다.

class Constant { 
    static BASE_URL = 'https://xxxxx'; 
    static URL_API_SERVER = Constant.BASE_URL + '/api/v2'; 
    static STATIC_BASEURL = Constant.BASE_URL + '/static'; 
    static URLSTRING_FAQ = Constant.STATIC_BASEURL + '/FAQ.html'; 
    static URLSTRING_TOU = Constant.STATIC_BASEURL + '/TOU.html'; 
} 

export default Constant; 
관련 문제