JavaScript DHTML/Ext JS/ArrayReader

Материал из Web эксперт
Перейти к: навигация, поиск

ArrayReader and Store

  
<html>
<head>
<title>Hello World Window</title>
<link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" />
<script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-3.0.0/ext-all.js"></script>
</head>
<script type="text/javascript">
Ext.onReady(function() {
      var store = new Ext.data.Store({
      data: [
        [1,"A","D","2009-02-19",1,"asdf",19.95,true],
        [3,"B","E","2002-02-15",1,"asdf",14.95,1],
        [4,"C","F","2009-10-01",2,"asdf",19.95,true]
        ],
      reader: new Ext.data.ArrayReader({id:"id"}, [
        "id",
        "title",
        "director",
        {name: "released", type: "date", dateFormat: "Y-m-d"},
        "genre",
        "tagline",
        {name: "price", type: "float"},
        {name: "available", type: "bool"}
      ])
      });
  
      var grid = new Ext.grid.GridPanel({
      renderTo: document.body,
      frame:true,
      title: "Movie Database",
          height:200,
          width:520,
      enableColumnMove: false,
          store: store,
          columns: [
        {header: "Title", dataIndex: "title"},
        {header: "Director", dataIndex: "director"},
        {header: "Released", dataIndex: "released", renderer: Ext.util.Format.dateRenderer("m/d/Y")},
        {header: "Genre", dataIndex: "genre"},
        {header: "Tagline", dataIndex: "tagline"}
          ]
      });
});

</script>
<body>

</body>
</html>



Create Store from array reader and name mapping

   
<html>
<head>
<title>Hello World Window</title>
<link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" />
<script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-3.0.0/ext-all.js"></script>
</head>
<body>
<script type="text/javascript">
Ext.onReady(function() {
    
    var arrayData = [           
      ["A",   "AA"],
      ["B",   "BB"],
      ["C",   "CC"]
    ];

    var memoryProxy  = new Ext.data.MemoryProxy(arrayData);               
    
    var nameRecord = Ext.data.Record.create([                             
        { name : "letter",  mapping : 1  },                           
        { name : "groupName",       mapping : 2  }
    ]);
    
    var arrayReader = new Ext.data.ArrayReader({}, nameRecord);           
    
    var store = new Ext.data.Store({                                      
        reader : arrayReader,
        proxy  : memoryProxy
    });

});
</script> 
<div id="div1">asdf</div>
</body>
</html>