【问题标题】:Cannot call method 'substring' of undefined无法调用未定义的方法“子字符串”
【发布时间】:2011-09-09 09:48:20
【问题描述】:

这是我的代码:

Ext.define('Ext.app.Portal', {
    extend: 'Ext.container.Viewport',

    uses: ['Ext.app.PortalPanel', 'Ext.app.PortalColumn', 'Ext.app.GridPortlet', 'Ext.app.ChartPortlet'],

    getTools: function () {
        return [{
            xtype: 'tool',
            type: 'gear',
            handler: function (e, target, panelHeader, tool) {
                var portlet = panelHeader.ownerCt;
                portlet.setLoading('Working...');
                Ext.defer(function () {
                    portlet.setLoading(false);
                }, 2000);
            }
        }];
    },

    initComponent: function () {
        var content = '<div class="portlet-content">' + Ext.example.shortBogusMarkup + '</div>';

        Ext.apply(this, {
            id: 'app-viewport',
            layout: {
                type: 'border',
                padding: '0 5 5 5'
            }, //eo layout
            items: [{ //app-header : item 1 of app-viewport
                id: 'app-header',
                xtype: 'box',
                region: 'north',
                height: 40,
                html: 'My Portal'
            }, { //container : item 2 of app-viewport
                xtype: 'container',
                region: 'center',
                layout: 'border',
                items: [{ //app-options: item 1 of container
                    id: 'app-options',
                    title: 'Options',
                    region: 'west',
                    animCollapse: true,
                    width: 200,
                    minWidth: 150,
                    maxWidth: 400,
                    split: true,
                    collapsible: true,
                    layout: 'accordion',
                    layoutConfig: {
                        animate: true
                    },
                    items: [{ //portal: item 1 of app-options

                        title: 'portal',
                        autoScroll: true,
                        border: false,
                        iconCls: 'nav'
                    }, { //settings : item 2 of app-options
                        title: 'Settings',
                        html: '<div class="portlet-content">' + 'details ??' + '</div>',
                        border: false,
                        autoScroll: true,
                        iconCls: 'settings'
                    }] //eo items app-options
                }, { //item 2 of container    
                    id: 'app-portal',
                    xtype: 'tabpanel',
                    activeTab: 0,
                    region: 'center',
                    items: [{
                        title: 'tab1',
                        layout: 'column',
                        html: 'this is the first tab',
                        closable: true
                    }, {
                        title: 'tab2',
                        closable: true
                    } //eo tab2
                    ] //eo items tabpanel

                }]
            }] //eo   app-portal
        }); //eo apply

        this.callParent(arguments);
    },

    onPortletClose: function (portlet) {
        this.showMsg('"' + portlet.title + '" was removed');
    },

    showMsg: function (msg) {
        var el = Ext.get('app-msg'),
            msgId = Ext.id();

        this.msgId = msgId;
        el.update(msg).show();

        Ext.defer(this.clearMsg, 3000, this, [msgId]);
    },

    clearMsg: function (msgId) {
        if (msgId === this.msgId) {
            Ext.get('app-msg').hide();
        }
    }

});

任何帮助将不胜感激。

【问题讨论】:

    标签: extjs tabs portal extjs4


    【解决方案1】:

    首先...我尝试复制粘贴您的代码,并将其替换为门户示例,...
    我没有收到您的错误,没有substring 错误,但我在tabpanel 部分出现错误。我认为,错误是因为uses 配置(这是因为substrin,可以在classes.js 中找到)..

    在门户示例中,他们使用Ext.app.PortalPanelExt.app.PortalColumnExt.app.GridPortletExt.app.ChartPortlet
    但在您的脚本中您不使用它.. 只需删除 uses 部分,
    你不需要那个,你只需要tabpanel

    第二个,看classes.js文件没有tabpanel定义...
    如果您想无边界地操作门户..
    使用ext-all.js 而不是ext-core..

    改变这个:

    <script type="text/javascript" src="../../builds/ext-core.js"></script>
    <script type="text/javascript" src="../shared/examples.js"></script>
    <script type="text/javascript" src="classes.js"></script>
    <script type="text/javascript" src="portal.js"></script>
    

    到这里

    <script type="text/javascript" src="../../bootstrap.js"></script>
    <script type="text/javascript" src="../shared/examples.js"></script>
    <script type="text/javascript" src="portal.js"></script>
    

    【讨论】:

    • 非常感谢,我确实需要使用,我刚刚删除了该部分以确保错误不是来自它。我添加了引导程序,现在我有一个新错误:“正在恢复调试器:调试循环期间出错:TypeError:firstViewRangeElement 为空” 但现在我可以看到门户(不是白屏)但我看不到标签
    • 这很奇怪:我在 Firefox 中得到了这个错误,但在 chrome 中,我没有得到错误(除了缺少 png)。但我仍然看不到标签,我可以看到我放在第一个的 html 内容,但看不到标签!!
    • 尝试通过创建一个包含标签面板的窗口来注入你的萤火虫,...如果可以的话,。这也让我感到困惑......
    • 不明白你想让我做什么!!如果我们忘记了 firefox,因为在 chrome 中我没有错误,为什么标签没有显示??
    • 我现在在 firefox 中也没有错误 :) (虽然不知道我做了什么 :p)。现在,如果我能知道如何显示标签...
    【解决方案2】:

    对于其他可能看到“无法调用未定义的方法'子字符串'”的人,当我看到这个时,通常是因为找不到别名。通常是一个糟糕的 xtype。例如,如果我使用xtype: 'img' 而不是xtype: 'image'。我通过查看“instantiateByAlias”的堆栈跟踪并查看该调用的参数来调试它。其中之一是其中包含有问题的 xtype 的配置。

    【讨论】:

    • 谢谢 - 在instantiateByAlias 中设置断点救了我。很遗憾,当 xtype 未知时,Ext 没有抛出更具描述性的错误。
    【解决方案3】:

    tats 正确 通常是错误的 xtype。例如,如果我使用 xtype: 'img' 而不是 xtype: 'image'。会导致这个。

    【讨论】:

      猜你喜欢
      • 2013-03-16
      • 1970-01-01
      • 2012-01-02
      • 2012-05-28
      • 2015-01-29
      • 2012-11-05
      • 2014-06-01
      • 2013-11-14
      • 1970-01-01
      相关资源
      最近更新 更多