Ext JsonReader Json元素.getXX/accessor

<html>
<head>
<script>

 

    obj = {'id':'id1','cls':{'name':'name11','type':'type432'}}


    getJsonAccessor = function(){


        var re = /[\[\.]/;
        return function(expr) {

                return(re.test(expr))
                    ? new Function("obj", "return obj." + expr)
                    : function(obj){
                        return obj[expr];
                    };

        };


    }()


</script>
</head>


<script>

...

map["id"]  =  getJsonAccessor("id"))  //返回funtion(obj)..

map["cls.name"]  =  getJsonAccessor("cls.name"))

map["cls.type"]  =  getJsonAccessor("cls.name"))

 

alert(map["id"](obj))      //   obj.getId()       IdAccessor(obj)

 

</script>

 

 

你可能感兴趣的:(html,json,ext)