【问题标题】:Can't get data from store to show up as the model无法从商店获取数据以显示为模型
【发布时间】:2011-09-26 19:24:38
【问题描述】:

我对 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');
}

视口首先加载主视图,这就是我遇到的问题。 这是我的家庭名片:

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:

{"feeds":[{"name":"Links","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?type=link","sort_order":"1"}],"updated":[{"last_updated":"2011-06-09 11:15:47"}]}

问题是这个视图上什么都没有显示,我怀疑模型可能有问题? 我已经登录了商店,我可以看到它获取了应有的数据。

有人有解决此问题的建议吗?

提前致谢


EDIT(得到关于 DataView 的提示): 扩展面板更改:

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'
    })
});

【问题讨论】:

    标签: model sencha-touch store


    【解决方案1】:

    目前设置为由Ext.Dataview 而非Ext.Panel 处理。任何继承 Ext.Component 形式的东西都可以传递一个 datatpl 参数,并导致将数据传递到 tpl 的结果加载到正文中。

    但是,您正在使用 store 来处理未内置在 Ext.Panel 类中的数据。如果您转换为Ext.Dataview 并定义必要的参数(当您尝试在没有所有必要参数的情况下创建一个时会引发错误),那么您的模板/面板将正确显示。

    【讨论】:

    • 您好,感谢您的回答。我试图将其更改为 dataview 并按我应该的方式提供 tpl、store 和 itemSelector,但它一直给我错误消息:“未捕获的 DataView 需要定义 tpl、store 和 itemSelector 配置。”。我已经编辑了我的第一篇文章,所以你可以看到我做了什么。
    • 您是否尝试将 Ext.Dataview 实例中的 tpl 参数设置为空字符串?
    • 我不得不继续前进,所以我放弃了 DataView 并尝试了其他方法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    • 1970-01-01
    • 2018-09-08
    • 2018-09-27
    • 2012-05-03
    相关资源
    最近更新 更多