我正在使用Rhomobile并试图动态地为Alert.show_popup的按钮的ID和标题生成一个哈希,但我并没有完全明白。我想最终的结果是什么是,实际上是:在JSON中创建红宝石的多维数组或哈希
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)
}
)
任何ruby向导都可以帮助我吗?
你确定你想要一个哈希? 'buttons'是你第一个例子中的一个数组。 –