任何人都可以向我解释这行代码
<% child_nodes = node.is_a?(Department) ? node.offices.where(parent_office_id: nil) : node.branch_offices %>
我很困惑?:
这叫什么?:
所以这个语句包含一个三元运算符: child_nodes = node.is_a?(Department) ?
如果它评估为真,则执行第一个条件,即: node.offices.where(parent_office_id: nil)
否则运行此代码: node.branch_offices
希望这可以帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句