且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

递归JSON解析器中的错误在哪里?

更新时间:2022-04-05 08:50:31

我修改了递归部分,现在看起来更加优雅。所有的xtype工作都很好,除了gridpanel,我已经检查了DOM,一切都在那里,但仍然有错误信息:

I modified the recursion part, it looks more elegant now. All the xtype works just fine, except gridpanel, I've check DOM, everything is in there, but still got error message:

TypeError: c is undefined
...+g.extraBaseCls);delete g.autoScroll;if(!g.hasView){if(c.buffered&&!c.remoteSort...  
ext-all.js (line 21, col 1184416)

我怀疑这是一个ExtJS错误

I suspect it's an ExtJS bug. I'll try to find another way out.

递归程序:

recursiveParser: function (jsonData) {
    var me = this;
    var properties = {};

    for ( var key in jsonData ){
        var value = jsonData[key];
        var items = (value.constructor === Array) ? [] : {};
        if (value instanceof Object) {
            if (isNaN(key)){
                if (items.constructor === Array) {
                    for (var node in value){
                        items.push(me.recursiveParser(value[node]));
                    }
                    properties[key] = items;

                } else {
                    properties[key] = me.recursiveParser(value);
                }
            } else {
                return me.recursiveParser(value);
            }
        } else {
                if (key.toString().indexOf('@') === 0){
                    key = key.replace('@', '');
                    properties[key] = value;
                }                    
        }
    }
    return properties;
}