0

私はこれにこだわっています:

アプリにデータを入力する必要があります。

プロモーションを初めて使用しています....

ProMotion がなければ、init メソッドでデータを取得するために使用します

今私のコードは以下のようになります:

class Parties < ProMotion::TableScreen
  attr_accessor :_cells
  @news = []
  include MyUiModules
  title 'Yazarlar'
  refreshable callback: :on_refresh,
     pull_message: "Pull to refresh",
     refreshing: "Refreshing data…",
     updated_format: "Last updated at %s",
     updated_time_format: "%l:%M %p"
 def on_refresh
   #MyItems.pull_from_server do |items|
   #@my_items = items
   end_refreshing
   #update_table_data
   # end
 end

 def table_data
   _cells = []
   [{
     title: nil,
     cells: create_cells(_cells)
   }]            
 end
 def will_appear
    Barbutton.create_bar(self)
    set_attributes self.view, {
      backgroundColor: hex_color("DBDBDB")
    }        
  end

  def go_to_next
    App.delegate.slide_menu.show_menu    
  end

  def create_cells(_cells)

   BW::HTTP.get(URL) do |response|
     json = BW::JSON.parse response.body.to_str
     for line in json
       _cells << { title: line["val_for_title"]}
     end
   end
   _cells
  end
end  

残念ながら、これは空の配列を返しますが、それを解決する方法がわかりません。助けてくれてありがとう

4

1 に答える 1

3

BW::HTTP.get は非同期であるため、それはできません。

代わりに、次のようにしてみてください。

def on_init
  @data = []
end

def table_data
  [
    {
      title: nil,
       cells: @data
     }
  ]            
end

def on_refresh
  BW::HTTP.get(URL) do |response|
    @data = []
    json = BW::JSON.parse(response.body.to_str)
    json.each do |hash|
      @data << { title: hash["val_for_title"]}
    end
    update_table_data
    end_refreshing
  end
end

それが役に立てば幸い :-)

于 2013-07-30T12:31:53.773 に答える