1

我的哈希数组是下面的。

[{"status"=>"Submitted", "reachable"=>false}, 
{"status"=>"Replied", "reachable"=>false}, 
{"status"=>"Answered", "reachable"=>false}, 
{"status"=>"Assigned", "reachable"=>false}, 
{"status"=>"Started", "reachable"=>true}, 
{"status"=>"Closed", "reachable"=>false}, 
{"status"=>"Canceled", "reachable"=>true}]

我需要“ status”值并将它们显示在带有嵌入 ruby​​ 代码的 html 中的下拉列表中。你们中的任何人都可以让我知道示例代码吗?我对 ruby​​ 非常陌生,并且在迭代和在下拉列表中显示值时感到很困惑。

4

1 回答 1

3

是的,如下:

array = [{"status"=>"Submitted", "reachable"=>false}, 
        {"status"=>"Replied", "reachable"=>false}, 
        {"status"=>"Answered", "reachable"=>false}, 
        {"status"=>"Assigned", "reachable"=>false}, 
        {"status"=>"Started", "reachable"=>true}, 
        {"status"=>"Closed", "reachable"=>false}, 
        {"status"=>"Canceled", "reachable"=>true}]

p array.map{|h| h["status"] }
# >> ["Submitted", "Replied", "Answered", "Assigned", "Started", "Closed", "Canceled"]
于 2013-08-29T10:25:10.297 回答