【问题标题】:ExtJS 4 - Cannot read property 'substring' of undefinedExtJS 4 - 无法读取未定义的属性“子字符串”
【发布时间】:2014-07-30 13:08:51
【问题描述】:

我是 Ext JS 4 的新手,我目前正在开发一个非常复杂的 Ext JS MVC 应用程序,它遵循本(基本)教程中解释的架构。

http://docs.sencha.com/extjs/4.0.7/#%21/guide/application_architecture

几乎所有时候我都会添加一个带有相关模型、控制器和存储的新视图,作为第一步,我必须修复一些拼写错误的别名或 ID。这变得非常棘手,因为 ext 并没有像我期望的那样帮助我,并且有很多这样的 id 需要寻找。

使用Firebug,给我的错误信息是:

Uncaught TypeError: Cannot read property 'substring' of undefined localhost:8080/Web/extjs4/ext-debug.js:5246

有没有办法快速找出拼写错误的位置?

这是引发异常的代码部分

 parseNamespace: function(namespace) {

            var cache = this.namespaceParseCache,
                parts,
                rewrites,
                root,
                name,
                rewrite, from, to, i, ln;

            if (this.enableNamespaceParseCache) {
                if (cache.hasOwnProperty(namespace)) {
                    return cache[namespace];
                }
            }

            parts = [];
            rewrites = this.namespaceRewrites;
            root = global;
            name = namespace;

            for (i = 0, ln = rewrites.length; i < ln; i++) {
                rewrite = rewrites[i];
                from = rewrite.from;
                to = rewrite.to;
                // 5246 
                if (name === from || name.substring(0, from.length) === from) {
                    name = name.substring(from.length); 

                    if (typeof to != 'string') {
                        root = to;
                    } else {
                        parts = parts.concat(to.split('.'));
                    }

                    break;
                }
            }

            parts.push(root);

            parts = parts.concat(name.split('.'));

            if (this.enableNamespaceParseCache) {
                cache[namespace] = parts;
            }

            return parts;
        },

提前致谢。

【问题讨论】:

    标签: javascript extjs4


    【解决方案1】:

    我用 console.log(Ext.getClassName(someObj)); -- 有时 JSLint 可以帮助您找到未使用的变量 -- 祝你好运!

    【讨论】:

    • 一个好的做法是让 id 尽可能简单。
    猜你喜欢
    • 2016-05-28
    • 2013-04-24
    • 1970-01-01
    • 2021-08-13
    • 2021-03-12
    • 2018-04-25
    • 1970-01-01
    • 2022-01-15
    • 2020-08-30
    相关资源
    最近更新 更多