我的哈希数组是下面的一个。
[{"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很新,并且在迭代中混淆并在下拉列表中显示值。
答案 0 :(得分: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"]