2011-07-01 55 views
0

我對Sencha Touch有點新,所以請耐心等待。無法從商店獲取數據以顯示爲模型

在應用程序啓動時,我將視口設置爲我使用的視口,並將所有視圖設置爲應用程序名稱空間。

launch: function() { 
     this.views.viewport = new this.views.Viewport(); 
     this.views.homecard = this.views.viewport.getComponent('home'); 
     this.views.usercard = this.views.viewport.getComponent('user'); 
     this.views.infocard = this.views.viewport.getComponent('info'); 
} 

該視口首先加載主視圖,這是我遇到的問題。 這是我homecard:

ToolbarDemo.views.Homecard = Ext.extend(Ext.Panel, { 
    title: "Meny", 
    iconCls: "home", 
    scroll: "vertical", 
    bodyStyle: "background-color: #FFFFFF !important; background-image:      url(images/background.png) !important; background-repeat:no-repeat; background-position:bottom left;", 
    initComponent: function() 
    { 
     ToolbarDemo.views.Homecard.superclass.initComponent.apply(this, arguments); 
    }, 
    store:ToolbarDemo.stores.feedStorer, 
    tpl:buttonTemplate, 
    dockedItems: 
    [ 
     { 
     xtype: "toolbar" 
     } 
    ], 
    defaults: {height: "110px"}, 

}); 

這裏是我的模板:

var buttonTemplate = new Ext.Template 
(
    '<tpl for=".">', 
    ' <div class="home_button_container">', 
    '  <img class="home_button" src="{url_icon_large}" />', 
    '  <p class="home_button_text">{name}</p>', 
    ' </div>', 
    '</tpl>' 
); 

這裏是我的模型:

Ext.regModel('Feeds', { 
    fields: [ 
     {name: 'name', type: 'string'}, 
     {name: 'url_icon_small', type: 'string'}, 
     {name: 'url_icon_medium', type: 'string'}, 
     {name: 'url_icon_large', type: 'string'}, 
     {name: 'url_icon_large_p', type: 'string'}, 
     {name: 'url', type: 'string'}, 
     {name: 'sort_order', type: 'string'} 
    ] 
}); 

這裏是我的店:

ToolbarDemo.stores.feedStore = new Ext.data.Store({ 
    model: 'Feeds', 
    storeId: 'feedStore', 
    proxy: { 
     type: 'scripttag', 
     url : 'http://localhost/webservice/feeds.php?username=' + sUsername + '&password=' + sPassword, 
     reader: { 
      type: 'json', 
      root: 'feeds' 
     } 
    }, 
    autoLoad: true 
}); 

這裏的JSON:

{ 「飼料」:[{ 「Name」: 「鏈接」, 「url_icon_small」: 「HTTP:URL/link_small.png」, 「url_icon_medium」: 「URL/link_medium.png」, 「url_icon_large」 : 「URL/link_large.png」, 「URL」: 「?URL/feed_content.php類型=鏈接」, 「排序順序」: 「1」}], 「已更新」:[{ 「LAST_UPDATED」:「2011-06- 09 11:15:47「}]}

問題是沒有任何顯示在這個視圖上,我懷疑它可能是錯誤的模型? 我已經登錄商店,我可以看到它獲得了它應該的數據。

任何人都有一個建議來解決這個問題?

預先感謝


EDIT(約DataView的GOT尖): Ext.Panel變化:

ToolbarDemo.views.Homecard = new Ext.Panel({ 

    title: "Meny", 
    iconCls: "home", 
    scroll: "vertical", 
    bodyStyle: "background-color: #FFFFFF !important; background-image: url(images/background.png) !important; background-repeat:no-repeat; background-position:bottom left;", 
    initComponent: function() 
    { 
     ToolbarDemo.views.Homecard.superclass.initComponent.apply(this, arguments); 
    }, 
    dockedItems: 
    [ 
     { 
     xtype: "toolbar" 
     } 
    ], 
    defaults: {height: "110px"}, 
    items: new Ext.DataView(
    { 
     tpl:buttonTemplate, 
     store: ToolbarDemo.stores.feedStorer, 
     autoHeight:true, 
     multiSelect: true, 
     loadingText: 'Laster data', 
     itemSelector:'div.home_button_container', 
     emptyText: 'No images to display' 
    }) 
}); 

回答

0

這是當前設置要由Ext.Dataview,而不是一個來處理Ext.Panel。任何繼承形式Ext.Component的東西都可以通過datatpl參數,並導致身體加載將數據傳遞到tpl的結果。

但是,您正在使用store來處理未構建到Ext.Panel類中的數據。如果您轉換爲Ext.Dataview並定義必要的參數(當您嘗試創建一個沒有所有必要參數時它會引發錯誤),那麼您的模板/面板將正確顯示。

+0

嗨,謝謝你的回答。我試圖將其更改爲dataview併爲我提供tpl,store和itemSelector,但它一直給我提供errormessage:「未捕獲的DataView需要tpl,store和itemSelector配置才能定義。」我編輯了我的第一篇文章,所以你可以看看我做了什麼。 – Ikky

+0

您是否嘗試過將Ext.Dataview實例化中的tpl參數設置爲空字符串? – Ballsacian1

+0

我不得不繼續前進,所以我放棄了DataView並嘗試了其他方法 – Ikky