我正在使用 Rhomobile 并尝试为 Alert.show_popup 的按钮的 id 和标题动态构建哈希,但我不太明白。实际上,我希望最终结果是:
Alert.show_popup( {
:message => 'Please Select Appropriate Address:',
:title => 'Get Nearby...',
:icon => :info,
:buttons => [
{'id' => '1', 'title' => 'Address 1'},
{'id' => '2', 'title' => 'Address 2'},
{'id' => '3', 'title' => 'Address 3'},
{'id' => '4', 'title' => 'Address 4'}
],
:callback => url_for(:action => :on_addressidentified_popup)
}
)
我尝试了几种方法,但都没有奏效(构建一个看起来像哈希和 try_convert 的字符串等)。这是我尝试过的最新的一个,它看起来很近,但仍然很远:
nearbyaddresses = Rho::JSON.parse(@params['body'])
h = {}
nearbyaddresses.each do |location|
h[intIndex] = {}
h[intIndex][:id] = intIndex.to_s
h[intIndex][:title] = location["Address"].to_s
intIndex = intIndex + 1
end
Alert.show_popup( {
:message => 'Please Select Appropriate Address:',
:title => 'Get Nearby...',
:icon => :info,
:buttons => h,
:callback => url_for(:action => :on_addressidentified_popup)
}
)
这里有任何红宝石向导可以帮助我吗?