【问题标题】:Sencha Touch 2 - JSONP proxy help, template always has null for valuesSencha Touch 2 - JSONP 代理帮助,模板的值始终为 null
【发布时间】:2012-04-02 03:25:07
【问题描述】:

我无法将实际数据显示在 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'));
    }
});

【问题讨论】:

    标签: javascript model sencha-touch jsonp sencha-touch-2


    【解决方案1】:
    root : 'data',
    totalCount : 'num_rows'
    

    已弃用。使用:

    rootProperty: 'data',
    totalProperty: 'num_rows'
    

    确保您包含来自sencha-touch-all-compat.js 的 Sencha Touch 用于开发。它会在浏览器控制台中报告您使用的所有已弃用的东西。

    【讨论】:

    • Arrrrgh,就是这样。经过一整天的努力,我终于切换到 jQuery Mobile,看看我是否会有更好的运气。 Sheesh,也许我现在会回到 Sencha Touch 2。对他们来说,“弃用”意味着“完全取出”,这似乎是蹩脚的。我在网上找到了很多现在不适用的 Sencha Touch 教程,因为 v2 已经弃用/删除了很多。
    【解决方案2】:

    我也在努力显示我的列表并在此搜索很多。

    在我看来改变这个后终于得到了我的答案:

    extend: 'Ext.Container',
    

    extend:'Ext.navigation.View',
    

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

    Sencha Touch 2: data intigration or how to share dynamic information between sencha and javascript

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

    希望对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-05-05
      • 2012-05-23
      • 2012-09-05
      • 2014-03-30
      • 2012-05-26
      • 1970-01-01
      • 1970-01-01
      • 2015-08-04
      • 1970-01-01
      相关资源
      最近更新 更多