2016-07-14 2 views
0

내 HAML 파일 :AngularJS와 : 삼항 연산자 조건 검사에서 기능 통화

%pipes-autocomplete{:model =>"filter.value",:option => "validate_option(filter)" ? "dependant(filter)" : "filter.option"} 

내 커피 스크립트 :

$scope.validate_option =(filter)-> 
    console.log "called validate_option" 
    if filter.hasOwnProperty('option') && filter.option.indexOf('dependant') > -1 
     return true 
    else 
     return false 
    $scope.dependant =(cal)-> 
    return "choosed" 

나는 validate_option 기능에 정의 된 호출 할 노력하고있어 삼항 연산자에서 내 함수가 호출되지 않습니다. 누군가이 문제를 도와 줄 수 있습니까?

+0

3 진 연산자는 문자열을 참으로 간주합니다 (공백이 아니기 때문에). validate_option (filter)? dependent (filter) : filter.option "'(모두 하나의 문자열)을 시도해보십시오. 그러면 문자열이 평가 될 때까지 삼항 연산자의 실행을 연기 할 수 있습니다. – trincot

+0

@ 트렁크 정말 고마워요. 괜찮아. 난 모르는 새비데. 너의 설명으로 내 의심이 사라졌어. –

답변

2

질문에 넣으면 삼원 연산자는 "validate_option(filter)" 문자열이 true (공백이 아니기 때문에)이라고 간주합니다.

대신 문자열 내부의 삼항 연산자를 넣어 :

"validate_option(filter) ? dependant(filter) : filter.option" 

당신이 문자열이 실제로 평가 될 때까지 삼항 연산자의 실행을 연기 그런 식으로.