六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 113|回复: 0

Ext JsonReader Json元素.getXX/accessor

[复制链接]

升级  36%

4

主题

4

主题

4

主题

童生

Rank: 1

积分
18
 楼主| 发表于 2013-2-7 19:23:48 | 显示全部楼层 |阅读模式
<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>  
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表