我正在使用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'是你第一個例子中的一個數組。 –