extjs:无法读取未定义的属性“子字符串”

Extjs: Cannot read property 'substring' of undefined

本文关键字:字符串 子字符串 属性 读取 未定义 extjs      更新时间:2023-09-26

嗨,我想在 Extjs 4.1.1 中将网格面板添加到我的视图中,但我在浏览器控制台中收到此错误"无法读取未定义的属性'子字符串'"。这是我的js代码:

Ext.require([
                  '*'
              ]);
     Ext.onReady(function(){
            Ext.tip.QuickTipManager.init();
            Ext.create('Ext.data.Store', {
                storeId:'simpsonsStore',
                fields:['name', 'email', 'phone'],
                data:{'items':[
                    { 'name': 'Lisa',  "email":"lisa@simpsons.com",  "phone":"555-111-1224"  },
                    { 'name': 'Bart',  "email":"bart@simpsons.com",  "phone":"555-222-1234" },
                    { 'name': 'Homer', "email":"home@simpsons.com",  "phone":"555-222-1244"  },
                    { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254"  }
                ]},
                proxy: {
                    type: 'memory',
                    reader: {
                        type: 'json',
                        root: 'items'
                    }
                }
            });
            Ext.create('Ext.grid.Panel', {
                title: 'Simpsons',
                store: Ext.data.StoreManager.lookup('simpsonsStore'),
                columns: [
                    { text: 'Name',  dataIndex: 'name' },
                    { text: 'Email', dataIndex: 'email', flex: 1 },
                    { text: 'Phone', dataIndex: 'phone' }
                ],
                height: 200,
                width: 400,
                renderTo:  Ext.Element.get('test')
            });
        });

这是 HTML 代码:

   <div id="test"> </div>

通过 ID 获取元素的正确方法是: Ext.get("my-div");http://www.objis.com/formationextjs/lib/extjs-4.0.0/docs/api/Ext.core.Element.html

所以我认为您需要将renderTo: Ext.Element.get('test')更改为:renderTo: Ext.get('test')