CodeParser

class webix.CodeParser()

Codeparser mixin

References

helpers
isArray(), isDate().

External references

Official documentation page.

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
webix.CodeParser = {
    //converts a complex object into an object with primitives properties
    collapseNames:function(base, prefix, data){
        data = data || {};
        prefix = prefix || "";

        if(!base || typeof base != "object")
            return null;

        for(var prop in base){
            if(base[prop] && typeof base[prop] == "object" && !webix.isDate(base[prop]) && !webix.isArray(base[prop])){
                webix.CodeParser.collapseNames(base[prop], prefix+prop+".", data);
            } else {
                data[prefix+prop] = base[prop];
            }
        }
        return data;
    },
    //converts an object with primitive properties into an object with complex properties
    expandNames:function(base){
        var data = {},
            i, lastIndex, name, obj, prop;

        for(prop in base){
            name = prop.split(".");
            lastIndex = name.length-1;
            obj = data;
            for( i =0; i < lastIndex; i++ ){
                if(!obj[name[i]])
                    obj[name[i]]  = {};
                obj = obj[name[i]];
            }
            obj[name[lastIndex]] = base[prop];
        }

        return data;
    }
};