【问题标题】:sencha touch - list display煎茶触摸列表显示
【发布时间】:2011-10-04 05:55:39
【问题描述】:

我正在尝试从数据库中提取少量记录并将其显示为一个面板(或屏幕)上的列表。但我在屏幕上看不到任何东西。请帮助我哪里错了。

服务器返回 JSON 响应

{"success":true,"savedDeals":[
{"dealId":"17","dealName":"$2 Off Any Sandwich","dealText":"Valid with the purchase of any drink on Tuesday through Thursday from 11am to 4pm. Cannot be combined with other offers.","dealCategory":"Restaurant","dealCount":"0","dealRemaining":99999},
{"dealId":"21","dealName":"$10 OFF Kid's Clothing & Gifts","dealText":"Spend $50 and receive $10 off your total purchase","dealCategory":"Baby\/Kids","dealCount":"3","dealRemaining":3}
]}

模型看起来像:

myapp.models.SavedDeals = Ext.regModel("myapp.models.savedDeals", {

     fields: [
        {name : "dealId", type: "int"},
        {name : "dealName", type : "string"},
        {name : "dealText", type : "string"},
        {name : "dealImg", type : "string"},
        {name : "dealCategory", type : "string"},
        {name : "dealCount", type : "int"},
        {name : "dealRemaining", type : "int"},

    ]

 });

这家店的样子

myapp.stores.SSavedDeals = new Ext.data.Store({
model: 'myapp.models.savedDeals',
autoload: true,
id : 'savedDealsStore',
proxy: {
    type: 'ajax',
    url: '/myappfiles/savedDeals.php',
    params: {
        UserID: '62'
    },      
    reader: {
        type: 'json',
        root: 'savedDeals',

    }
},

});

视图看起来像

        myapp.views.DealraiserSavedDeals = Ext.extend(Ext.Panel,{ 

        fullscreen : true,

        standardSubmit : false,

        dockedItems: [{
            xtype: 'toolbar',
            title: 'Deals List',
            dock: 'top',
            items: [{
                xtype: 'button',
                text: 'Home',
                ui: 'Home',
                handler: function(){                     
                  myapp.views.viewport.setActiveItem(myapp.views.dealraiserHome , 'slide');
                }

            }]
        },
        ],

       items: [{
         xtype: 'list',
         id : 'savedList',
         emptyText   : 'No data available.',
         store: myapp.stores.SSavedDeals,
         itemTpl: '{dealName}'
       }]

       initComponent: function() {
         myapp.stores.SSavedDeals.load();
         myapp.views.DealraiserHome.superclass.initComponent.apply(this, arguments);
       }
 });

请帮忙,我应该怎么做才能解决这个问题。

谢谢。

【问题讨论】:

    标签: sencha-touch


    【解决方案1】:

    我认为罪魁祸首是你正在调用不同类的“超类”initComponent 方法,如果这有意义的话!

    initComponent: function() {
        myapp.stores.SSavedDeals.load();
        myapp.views.**DealraiserSavedDeals**.superclass.initComponent.apply(this, arguments);
    }
    

    在 initComponent 定义之前的 'items' 数组之后,您还缺少一个逗号。

    进行这些更改后,列表会在本地副本中为我显示 - 唯一的区别是我将数据作为数组而不是从您的 PHP 文件加载。

    【讨论】:

    • 我进行了这些更改并尝试通过使用“数据:”属性从存储本身加载数据来测试它。有效。但是,数据不是从 php 文件中加载的。关于如何从 php 文件加载数据的任何建议。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多