0

我正在尝试通过在 sencha touch 文档示例中生成的 Oreilly 应用程序示例来学习 sencha touch。Ext.getStore函数返回undefined

代码:

Ext.application({
    //name space of application
    name: 'sample',

    title: '<img src="lib/resources/images/home.png"/>',

    webserviceUrl: 'http://xxx/yyy/zzz.svc/',

    requires: ['sample.util.Proxy'],

    view: [
        'Viewport',     
        'wares.lists.Popular',
        'wares.lists.List'
    ],

    model: [
        'WaresListItem'
    ],

    store: [
        'Wares'
    ],

    launch: function() {
        Ext.Viewport.setMasked({ xtype: 'loadmask' });

        sample.util.Proxy.process(function () {
            Ext.create('sample.views.Viewport');
            Ext.Viewport.setMasked(false);
        });     
    }
});

//------

Ext.define('sample.views.Viewport', {
    extend: 'Ext.tab.Panel',

    title:   'Hello world!',

    xtype: 'viewport',

    config: {
        fullscreen: true,

        tabBar: {
            docked: 'bottom',
        },

        items: [
            { xclass: 'sample.views.wares.lists.Popular' },
        ]
    }
});

//-----

Ext.define('sample.views.wares.lists.Popular', {
    extend: 'Ext.NavigationView',

    requires: ['sample.views.wares.lists.List'],

    xtype: 'Popular',

    config: {       
        iconCls: 'home',
        title: 'List',

        items: [
            {
                xtype: 'wares',                         
            }
        ]   
    }
});

//-----

Ext.define('sample.views.wares.lists.List', {
    extend: 'Ext.List',

    xtype: 'wares',

    config: {
        store: 'Wares', 
        itemTpl: {}
    },

    initialize: function () {
        this.config.title = sample.app.title;
    }
});    

//-----

Ext.define('sample.util.Proxy', {
    singleton: true,

    requires: ['Ext.Ajax'],

    process: function(callback) {
        var wareListStore = Ext.getStore('Wares'); //returns undefinded
        var wareModel;

        console.log("Store: ", wareListStore);

        Ext.Ajax.request({
            url: sample.app.webserviceUrl + 'getSomeItems',

            disableCaching: false,
            useDefaultXhrHeader: false,

            headers: {
                "Content-Type": "application/json"
            },

            method: 'POST',

            params: JSON.stringify({"Type":3}),

            success: function (response) {
                var result = JSON.parse(response.responseText);

                if(true === result.Header.Status) {             

                    Ext.Array.each(result.Body, function (ware) {
                        wareModel = Ext.create('sample.models.WaresListItem', ware);
                        // wareListStore.add(wareModel); //raises an error

                    });                 
                } else {
                    console.log("Error code: %i", result.Header.ErrorCode);     
                }               
            },

            failure: function (response) {
                console.log('Houston, we have a problem!');
                console.log(JSON.stringify(response));
            }
        });

        callback();     
    }   
});

//-----

Ext.define('sample.store.Wares', {
    extend: 'Ext.data.Store',

    config: {
        model: "sample.models.WaresListItem"
    }
});

我重写了一切,就像在一个例子中一样。我错过了什么?

更新:在控制台中,我看到存储对象脚本根本不包括在内。

4

2 回答 2

1

必须为数组名称赋予这些名称viewscontrollersmodelsstores。重命名数组修复了它。

于 2012-12-12T15:21:30.030 回答
0
Ext.define('sample.store.Wares', {
    extend: 'Ext.data.Store',

    config: {
        model: "sample.models.WaresListItem",
        storeId: 'Wares'
    }
});

试试这个应该可以......希望它有帮助......

于 2012-12-11T15:17:39.597 回答