2013-07-30 69 views
0

我被困在這個:Promotion/bubble-wrap TableScreen data

我需要將數據填充到我的應用程序。

我使用促進了第一次....

沒有推廣我使用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 

不幸的是,這確實會返回一個空數組,我無法弄清楚如何解決它。 Thx for your help

+0

https://github.com/clearsightstudio/ProMotion/issues/248#issuecomment-21821293 – silasjmatson

回答

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 

希望它可以幫助:-)

相關問題