Sencha Touch 2-JSONP代理帮助,模板的值总是为null

Sencha Touch 2 - JSONP proxy help, template always has null for values

本文关键字:null 2-JSONP Touch 代理 帮助 Sencha      更新时间:2023-09-26

我在获取实际数据以显示在Sencha Touch 2列表中时遇到问题。该列表应该由一个JSONP响应填充,我预计会显示2行。相反,我得到了一行"null at null"。

以下是发送的URL:

http://some-server/data-fetcher.php?_dc=1331910031292&events=true&page=1&start=0
  &limit=25&callback=Ext.data.JsonP.callback1

以下是JSONP的回应:

Ext.data.JsonP.callback1({"data":[{"id":"4","name":"Sample Name 1",
  "description":null,"location":"Sample Location 1",
  "start_time":"2012-03-22 00:00:00","end_time":null},{"id":"5",
  "name":"Sample Name 2","description":null,"location":"Sample Location 2",
  "start_time":"2012-03-31 00:00:00","end_time":null}],"num_rows":2});

这是我的型号:

Ext.define('MyApp.model.Event', {
    extend: 'Ext.data.Model',
    config : {
        idProperty: 'id',
        fields : [ {
            name : "id",
            type : "int"
        }, {
            name : "name",
            type : "string"
        }, {
            name : "description",
            type : "string"
        }, {
            name : "location",
            type : "string"
        }, {
            name : "start_time",
            type : "date"
        }, {
            name : "end_time",
            type : "date"
        } ]
    }
});

这是我的商店:

Ext.define('MyApp.store.EventsOnline', {
    extend  : 'Ext.data.Store',
    requires: ['MyApp.model.Event'],
    config  : {
        model : 'MyApp.model.Event',
        autoLoad : true,
        proxy : {
            type : 'jsonp',
            url : 'http://some-server/data-fetcher.php',
            reader : {
                type : 'json',
                root : 'data',
                totalCount : 'num_rows'
            },
            callbackKey : 'callback',
            extraParams : {
                'events' : true
            }
        }
    }
});

这是我的观点:

Ext.define('MyApp.view.Event', {
    extend: 'Ext.Container',
    config : {
        layout : {
            type : 'vbox',
            align : 'stretch'
        },
        fullscreen : true,
        flex : 1,
        items : [
            {
                xtype : 'toolbar',
                docked : 'top',
                title : 'Events'
            }, {
                xtype   : 'list',
                flex    : 1,
                store : 'EventsOnline',
                itemTpl : '{name} at {location}'
            }
        ]
    }
});

我希望在我的列表中看到的是:

Sample Name 1 at Sample Location 1
Sample Name 2 at Sample Location 2

相反,我看到的是:

null at null

我做错了什么?

编辑:如果重要的话,这里是我的应用程序和控制器:

Ext.Loader.setConfig({enabled : true});
Ext.application({
    name               : 'MyApp',
    appFolder          : 'app',
    controllers : ['Home'],
    launch : function() {
        window[this.getName()].app = this;
    }
});
Ext.define('MyApp.controller.Home', {
    extend: 'Ext.app.Controller',
    models: ['Event'],
    stores: ['EventsOnline'],
    views: ['Event'],
    init: function () {
        var me = this;
        Ext.Viewport.add(Ext.create('MyApp.view.Event'));
    }
});
root : 'data',
totalCount : 'num_rows'

已弃用。用途:

rootProperty: 'data',
totalProperty: 'num_rows'

请确保您已将sencha-touch-all-compat.js中的Sencha Touch纳入开发中。它将在浏览器控制台中报告您使用的所有不推荐使用的内容。

我也很难显示我的列表,并在上面搜索了很多。

在改变了我的看法后,终于得到了我的答案:

extend: 'Ext.Container',

extend:'Ext.navigation.View',

我从下面的示例链接中得到了以上线索!

Sencha Touch 2:数据初始化或如何在Sencha和javascript 之间共享动态信息

它现在正在工作,很高兴看到我的第一个MVC示例正在工作:)

希望它能帮助到别人。