0

谁能帮我写一些代码:),我有闲散的哈希

selector = {
 :fields => ['Id'],
 :predicates => [
   {:field => 'grpId', :operator => 'EQUALS', :values => [params_id]},
   {:field => 'CrType', :operator => 'EQUALS', :values => ['KEYWORD']}
 ]
}

我想为这条线创造一个条件:

{:field => 'grpId', :operator => 'EQUALS', :values => [params_id]},

仅当 params_id 不为空时才执行。

谢谢

4

1 回答 1

0
selector = {
 :fields => ['Id'],
 :predicates => [
   params_id ? {:field => 'grpId', :operator => 'EQUALS', :values => [params_id]} : nil,
   {:field => 'CrType', :operator => 'EQUALS', :values => ['KEYWORD']}
 ].compact
}
于 2013-08-19T14:00:26.023 回答