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