2011-07-01 54 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