ITeye博客

Ext JsonReader Json元素.getXX/accessor

side91 · 2009-08-16 03:11 · ExtJs · Markdown

<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>

 

评论(1)

  1. #1 楼 · side91 · 2009-08-16 03:17

    json 子属性 也为对象 或数组::http://side91.iteye.com/admin/blogs/445510

评论功能维护中,当前仅展示历史评论。