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非常感谢。它工作正常。我是一个新手角。我的疑惑已经与您的解释清除。 –