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

I'm having trouble getting actual data to show up in a Sencha Touch 2 list.The list should be po

I'm having trouble getting actual data to show up in a Sencha Touch 2 list. The list should be populated by a JSONP response, and I expect 2 rows to show up. Instead, I get one row with 'null at null'.

Here's the URL that gets sent:

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

Here's the JSONP response:

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

Here's my model:

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"
        } ]
    }
});

Here's my store:

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

Here's my view:

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

What I expect to see in my list is:

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

And instead all I see is:

null at null

What am I doing wrong?

Edit: if it matters, here are my app and controller:

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

I'm having trouble getting actual data to show up in a Sencha Touch 2 list. The list should be populated by a JSONP response, and I expect 2 rows to show up. Instead, I get one row with 'null at null'.

Here's the URL that gets sent:

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

Here's the JSONP response:

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

Here's my model:

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"
        } ]
    }
});

Here's my store:

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

Here's my view:

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

What I expect to see in my list is:

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

And instead all I see is:

null at null

What am I doing wrong?

Edit: if it matters, here are my app and controller:

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'));
    }
});
Share Improve this question edited Mar 16, 2012 at 15:12 Sarah Vessels asked Mar 16, 2012 at 15:07 Sarah VesselsSarah Vessels 31.7k33 gold badges159 silver badges224 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3
root : 'data',
totalCount : 'num_rows'

Is deprecated. Use:

rootProperty: 'data',
totalProperty: 'num_rows'

Make sure you included Sencha Touch from sencha-touch-all-pat.js for development. It'll report in the browser console all deprecated things that you use.

I was also struggling to display my list and searching lot on this.

Finally got my answer after changing this in my view:

extend: 'Ext.Container',

to

extend:'Ext.navigation.View',

I got the above clue from the example link below!

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

It now working, happy to see my first MVC example working :)

Hope it help someone.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745491972a4630024.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信