【问题标题】:Extjs: Cannot read property 'substring' of undefinedExtjs:无法读取未定义的属性“子字符串”
【发布时间】:2016-05-28 22:51:31
【问题描述】:

嗨,我想在 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>

【问题讨论】:

  • 抱歉,您能粘贴控制台文本吗?我怎样才能找到未定义的内容?
  • 您正在对希望包含字符串但不是字符串的变量使用substring() 函数。堆栈跟踪(chrome 默认在控制台中提供,只需单击灰色三角形...)会非常有帮助。
  • 这是错误的快照:prntscr.com/a4dc7m
  • 同样的代码对我有用

标签: javascript extjs


【解决方案1】:

通过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')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-13
    • 2021-03-12
    • 2018-04-25
    • 1970-01-01
    • 2020-08-30
    • 2016-07-25
    • 2013-04-24
    相关资源
    最近更新 更多