`
baiyejianxin
  • 浏览: 159877 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Flex中存储key-value关系

    博客分类:
  • Flex
阅读更多



 

 

项目需要通过设备ID来存储当前设备的可用Ip地址,如果放在Array里面,每次去除deviceID对应的Ip地址需要遍历。所以想利用类似于Java中Map这种key-value的形式,对数据进行操作。

       果然,答案是Object类似于Java中的HashMap。

-------------

Demo1:添加数据

 

       var temp:Object = new Object();

 

       temp["ThinkPad"] = "10.1.1.1";

       temp["LePad"] = "10.1.1.3";

       temp["lePhone"] = "10.1.1.5";

 

-------------

Demo2:根据key删除当前记录

       delete temp["LePad"];

 

-------------

Demo3:  根据Key获取对应的记录

       var tempIp:String = temp["LePhone"];

 

-------------

Demo4: 关于Object的遍历---获取key

 

       for( var i:String in temp){

            Alert.show( "key =" + i);              //获取key值

            Alert.show( "key =" + temp[i]);    //获取value

       }

 

-------------

Demo5:关于Object的遍历----获取value

 

       for each( var ip:String in temp){

            Alert.show( "value =" + ip);

       }

  • 大小: 69.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics