Sencha Touch: Ext.DataView not showing store data

吃可爱长大的小学妹 提交于 2019-12-09 13:54:32

问题


I know the typical reason for a DataView to be blank is because the model or JSON is wrong. From what I can tell, mine is right... so I'm not sure why my DataView is blank.

Controller

rpc.controllers.AboutController = new Ext.Panel({
    id: 'rpc-controllers-AboutController',
    title: 'About',
    iconCls: 'info',
    layout: 'card',
    scroll: 'vertical',
    items: [rpc.views.About.index],
    dockedItems: [{ xtype: 'toolbar',
        title: 'RockPointe Church | Mobile'
    }],
    listeners: {
        activate: function () {
            if (rpc.stores.AboutStore.getCount() === 0) {
                rpc.stores.AboutStore.load();
            }
        }
    }
});

View

rpc.views.About.index = new Ext.DataView({
    id: 'rpc-views-about-index',
    itemSelector: 'div.about-index',
    tpl: '<tpl for="."><div class="about-index">{html}</div></tpl>',
    store: rpc.stores.AboutStore,
    fullscreen: true,
    scroll: 'vertical'
});

Store

rpc.stores.AboutStore = new Ext.data.Store({
    id: 'rpc-stores-aboutstore',
    model: 'rpc.models.AboutModel',
    autoLoad: true,
    proxy: {
        type: 'scripttag',
        url: WebService('About', 'Index'),
        method: 'GET',
        reader: {
            type: 'json',
            root: 'results'
        },
        afterRequest: function (request, success) {
            if (success) {
                console.log("success");
            } else {
                console.log("failed");
            }
            console.log(request);
        }
    }
});

rpc.stores.AboutStore.proxy.addListener('exception', function (proxy, response, operation) {
    console.log(response.status);
    console.log(response.responseText);
});

Model

rpc.models.AboutModel = Ext.regModel('rpc.models.AboutModel', {
    fields: ['html']
});

JSON

mycallback({"results":{"html":"... content removed for brevity ..."},"success":true});

Can anyone see what I might be doing wrong here?

There are no console/javascript errors. And the resources are showing that I am in fact pulling down the JSON from the WebService.

If I use console.log(rpc.stores.AboutStore.getCount()); inside my activate listener on the AboutController, the result is always 0, and I'm not entirely sure why

here's the staging app if you'd like to see the request
http://rpcm.infinitas.ws/ (note, this link will expire at some point)


回答1:


Try returning your json value as an array instead of an object. I think Ext is expecting an array of records instead of just one.

For example

"{results : [{"html": "Your html"}]}"



来源:https://stackoverflow.com/questions/6459656/sencha-touch-ext-dataview-not-showing-store-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!