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功能我角度控制器。但功能沒有被調用。有人可以幫我解決這個問題。
正如你現在所說的,三元運算符會認爲字符串是真的(只是因爲它不是空的)。使用'「validate_option(filter)?dependent(filter):filter.option」'(全部在一個字符串中)嘗試,以便將三元運算符的執行推遲到字符串求值時。 – trincot
@trincot非常感謝。它工作正常。我是一個新手角。我的疑惑已經與您的解釋清除。 –