Quentin
期待...Quentin
<html>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<head>
<link rel="stylesheet" type="text/css" href ="ext-2.0.2/resources/css/ext-all.css"/>
<script type="text/javascript" src="ext-2.0.2/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-2.0.2/ext-all.js"></script>
<script type="text/javascript" src="../lib/persistence.js"></script>
<script type="text/javascript" src="../lib/persistence.store.sql.js"></script>
<script type="text/javascript" src="../lib/persistence.store.websql.js"></script>
<script type="text/javascript" src="../lib/persistence.store.memory.js"></script>

<script type="text/javascript">
     function fn(){
          if(window.openDatabase){
               persistence.store.websql.config(persistence,'ds','test','5 * 1024 * 1024');
          }else{
               persistence.store.memory.config(persistence);
          }
          //persistence.reset();
          var User =persistence.define('Info',{
                         name:"TEXT",
                         age:"INTEGER",
                         sex:"TEXT"
                    });
          persistence.schemaSync();
               var w = new Ext.Window({
                    width:400,
                    height:200,
                    plain:true,
                    items:[
                    new Ext.Panel({
                    //renderTo:Ext.getBody(),
                    id:"inserlab",
                    title:"信息录入",
                    width:350,
                    height:150,
                    layout:"form",
                    items:[
                              {
                              id:"name",
                              xtype:"textfield",
                              fieldLabel:"姓名",
                              name:"name"},
                              {
                              id:"age",
                              xtype:"textfield",
                              fieldLabel:"年龄",
                              name:"age"},
                              {
                              id:"sex",
                              xtype:"textfield",
                              fieldLabel:"性别",
                              name:"sex"
                         }],
                    buttons:[
                         {
                         text:"确认",
                         handler:function(){
                              var n=Ext.getCmp("name").getValue();
                              var a=Ext.getCmp("age").getValue();
                              var s=Ext.getCmp("sex").getValue();
                              var mark =new User({name:n,age:a,sex:s});
                              var data =[name,age,sex];
                              persistence.add(mark);
                              persistence.flush();
                              //window.location.href="psn.html";
                              w.close();
                             
                              }
                         },
                    ],
                    buttonAlign:"center"
                    })]
});w.show();
}

     function createdata(){
          if(window.openDatabase){
               persistence.store.websql.config(persistence,'ds','test','5 * 1024 * 1024');
          }else{
               persistence.store.memory.config(persistence);
          }
          var User =persistence.define('Info',{
                         name:"TEXT",
                         age:"INTEGER",
                         sex:"TEXT"
                    });
          persistence.schemaSync();
          console.log("数据库和表被建立");
     }
     function fb(){
          if(window.openDatabase){
               persistence.store.websql.config(persistence,'ds','test','5 * 1024 * 1024');
          }else{
               persistence.store.memory.config(persistence);
          }
          var User =persistence.define('Info',{
                         name:"TEXT",
                         age:"INTEGER",
                         sex:"TEXT"
                    });
          persistence.schemaSync()
          persistence.reset();
          console.log("数据库被清理");
          window.location.href="ps.html";
     }    
     function dblist(){
          window.location.href="ps_ext.html";
     }
     function dn(){
          if(window.openDatabase){
               persistence.store.websql.config(persistence,'ds','test','5 * 1024 * 1024');
          }else{
               persistence.store.memory.config(persistence);
          }
          //persistence.reset();
          var User =persistence.define('Info',{
                         name:"TEXT",
                         age:"INTEGER",
                         sex:"TEXT"
                    });
          persistence.schemaSync();
          var i;
          for(i=0;i<500;i++){
               var mark =new User({name:'fdsaf',age:'fdsaaa',sex:'fadsfdsa'});
               persistence.add(mark);
               persistence.flush();
               if(i==499)
               {alert(i);
               break;
               }
          }
     }
</script>
</head>
<body>
     <input type="button" name="cr" value ="建立数据库" id="cre" onclick="createdata()"/>
     <input type="button" name="dd" value ="删除数据库" id="dele" onclick="fb()"/>
     <input type="button" name="data" value ="数据录入" id ="indata" onclick="fn()"/>
     <input type="button" name="data" value ="数据列表" id ="list" onclick="dblist()"/>
     <input type="button" name="data" value ="大数据" id ="das" onclick="dn()"/>

</body>
</html>
persistence.js 是一个 JavaScript 框架,最初它的设计目标是对 HTML Web SQL 进行 OR Mapping,以方便客户端开发人员进行快速的 Web SQL 访问。后来随着该框架的发展,它开始逐渐剥离了对数据库的依赖,成为一个可以支持各种数据库的框架。并且目前最新的版本也可以和服务器端框架,比如 Nodejs,RingoJS 一起工作。

 

posted on 2014-04-04 15:18  Quentins  阅读(604)  评论(0编辑  收藏  举报