【问题标题】:Ext.getStore() creating error: Uncaught TypeError: undefined is not a functionExt.getStore() 创建错误:Uncaught TypeError: undefined is not a function
【发布时间】:2014-07-23 04:54:40
【问题描述】:

我正在创建一个 ListView 并用我创建的商店中的一些数据填充它。

当我将商店分配给列表视图时,使用 store : Ext.getStore('Feeds'),我收到一个错误:

Uncaught TypeError: undefined is not a function

查看类:

Ext.define('Volt.view.FeedView', {
    extend: 'Ext.Panel',

    requires: [
        'Ext.TitleBar',
        'Ext.Button',
        'Ext.Toolbar'
        //'Ext.Panel'
    ],

    xtype: 'feedViewCard',

    config: {
        iconCls: 'action',
        title: 'FeedView',
        layout: {
            type: 'vbox'
        },
        items: [
            {
                xtype: 'feedlistview', // this is defined as a class that inherits from xtype = list
                store: Ext.getStore('Feeds'), //removing this line gives no error
                flex: 1,
                    }
                }
            }
        ]
    },
});

商店类

Ext.define("Volt.store.Feeds", {
    extend: "Ext.data.Store",
    requires: "Ext.data.proxy.LocalStorage",
    config: {
        model: "Volt.model.Feed",
        data: [
            { title: "Feed 1", narrative: "narrative 1" },
            { title: "Note 2", narrative: "narrative 2" },
            { title: "Note 3", narrative: "narrative 3" },
            { title: "Note 4", narrative: "narrative 4" },
            { title: "Note 5", narrative: "narrative 5" },
            { title: "Note 6", narrative: "narrative 6" }
        ],
        sorters:[
            {
                property: 'dateCreated',
                direction: 'DESC'
            }
        ]
    }
});

模型类

Ext.define("Volt.model.Feed", {
    extend: "Ext.data.Model",
    config: {
        idProperty: 'id',
        fields: [
            { name: 'id', type: 'int' },
            { name: 'dateCreated', type: 'date', dateFormat: 'c' },
            { name: 'title', type: 'string' },
            { name: 'narrative', type: 'string' }
        ],
        validations: [
            { type: 'presence', field: 'id'},
            { type: 'presence', field: 'dateCreated'},
            { type: 'presence', field: 'title', 'message': 'Enter a valid title'}
        ]
    }
});

【问题讨论】:

    标签: extjs sencha-touch


    【解决方案1】:

    您正试图在 定义 时间内获取该商店,而该商店尚不存在。如果Feeds store 列在应用程序或控制器的stores:[] 中,则只需将其设置为文本store:'Feeds'

    当应用程序初始化时,它会检测到 store 是一个字符串并为您调用 Ext.getStore。

    您可能还对Ext Component Life Cycle 和/或Ext Application Startup Sequence 感兴趣

    【讨论】:

    • 非常感谢。我在 ext.List 的初始化事件处理函数中使用 this.setStore() 函数进行了纠正,现在可以正常工作了。
    猜你喜欢
    • 1970-01-01
    • 2014-08-15
    • 2015-01-14
    • 2014-07-06
    • 2014-09-01
    • 2015-11-04
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多