0
我有一個從Rest中以JSON格式返回的對象數組,當我調試時我只能看到引用。我已將do循環添加到我的某個視圖中,但我沒有該對象的任何屬性。有什麼我需要做的像投擲數組?我是新來的紅寶石,並已搜索,沒有發現任何具體的。類對象的Ruby數組迭代返回查看
第一控制器不PolicyList
data3 = data2.map { |rd| PolicyList.new(rd["policyNbr"], rd["systemId"], rd["insuredName"], rd["type"], rd["statusCd"], rd["statusDes"], rd["payorZipcode"], rd["lastPaymentDate"], rd['lastPaymentAmount'], rd["pastDueDate"], rd["pastDueAmount"], rd["currentDueDate"], rd["currentDueAmount"], rd["eft"], rd["suspenseAmt"], rd["expireTime"]) }
$policylist =data3
puts data3.inspect
WebView.navigate(url_for(:controller => :PolicyList, :action => :index))
PolicyList控制器
def index
#@policylists = PolicyList.find(:all)
@policylists = $policylist
render :back => '/app'
end
PolicyList index.erb
<ul data-role="listview">
<% @policylists.each do |policylist| %>
<li>
<a href="<%= url_for :action => :show, :id => policylist.policyNbr %>">
<%= policylist.policyNbr %>
</a>
</li>
<% end %>
</ul>
PolicyList類
# The model has already been created by the framework, and extends Rhom::RhomObject
# You can add more methods here
class PolicyList
include Rhom::PropertyBag
attr_accessor :policyNbr, :systemId, :insuredName,
:type, :statusCd, :statusDes, :payorZipcode,
:lastPaymentDate,:lastPaymentAmount,:pastDueDate,
:pastDueAmount,:currentDueDate,:currentDueAmount,:eft,
:suspenseAmt,:expireTime
感謝響應。我檢查並且json消息到數組的格式爲[{「policyNbr」:「1」,「systemId」:「2」},{「policyNbr」:「3」,「systemId」:「4}] data 3 = [#,#,#] –
2013-03-04 19:26:35
好吧,這取決於您的類成員是如何聲明的這些字段在PolicyList類中聲明與attr_accessible? – 2013-03-04 20:34:59
這應該作爲OP的更新來完成,所以其他人可以更容易地看到它。 – BlackHatSamurai 2013-03-05 00:09:01