0

I have an array of objects returned from Rest in JSON format, when I debug I just see the reference. I have added the do loop to one of my views, but I don't have any properties of the object. Is there something I need to do like cast the array? I'm new to ruby and have searched and found nothing specific to this.

First controller not 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 Controller

      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 class

 # 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
4

1 回答 1

0

尝试检查 data2 变量(在映射之前)。
JSON 中的数据可能有一个根元素,如下所示:

[
 {"policy":{
   "policyNbr":"1",
   "systemId":"2"
   }
 },
 {"policy":{
   "policyNbr":"3",
   "systemI‌​d":"4"
   }
 }
]
于 2013-03-04T19:20:09.803 回答