zoukankan      html  css  js  c++  java
  • JS 数据存储

          /* 字典目录 数据存储 */
          var editData = {
           
          };
          editData.data = {};
          editData.Add = function (key, obj) {
              editData.data[key] = obj
          };
          
          editData.GetData = function ()
          {
              var data = editData.data;
              for (var key in editData.data)
                  alert(key+":"+data[key]);
          };
          editData.Delete = function (key) {
             delete  editData.data[key];
          };
    
          editData.Add("a1", 1);
          editData.Add("a2", 2);
          editData.Add("a3", 3);
          editData.Add("a4", 4);
          editData.GetData();
          editData.Delete("a3");
          editData.GetData();

     定义对象  输出JSON对象数据不同状态

      /* JSON.stringify:  <script  type="text/javascript" src="https://raw.github.com/douglascrockford/JSON-js/master/json.js"></script>*/
    
         var  j_str="[{key:\"key1\",val:11},{key:\"key2\",val:12},{key:\"key3\",val:13}]";
         var jsonObj=eval('('+j_str+')');
         var  len=jsonObj.length;
        
         // 输出 len= 3
    
         var  jobj={};
         jobj[0]={};
         jobj[0].key="key1";
         jobj[0].val=1;
         
         jobj[1]={};
         jobj[1].key="key2";
         jobj[1].val=2;
          
         jobj[2]={};
         jobj[2].key="key3";
         jobj[2].val=3;
         var str=JSON.stringify(jobj);
        
          /*
            str=[{"key":"key1","val":1},{"key":"key2","val":2},{"key":"key3","val":3}]
        
           将 var  jobj=new Array();  
            换成 var  jobj={};  
            JSON.stringify(jobj)
            则 输出:{"0":{"key":"key1","val":1},"1":{"key":"key2","val":2},"2":{"key":"key3","val":3}}
         */
        
  • 相关阅读:
    liunx下忘记mysql的密码
    oracle add_month函数
    oracle的LAST_DAY()函数
    JAVA方法中参数到底是值传递还是引用传递
    list=null和list.size=0的区别
    对python 函数的一些理解
    python 文件流
    html canvas 简单体验
    angular js 指令
    初识 angular js
  • 原文地址:https://www.cnblogs.com/rhythmK/p/3044234.html
Copyright © 2011-2022 走看看