-
Notifications
You must be signed in to change notification settings - Fork 0
/
stores-example.html
executable file
·86 lines (66 loc) · 2.2 KB
/
stores-example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<html>
<head>
<title>Stores</title>
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
<style>
body{
background-color:#aeaeae;
}
#container{
background-color:#ccc;
}
</style>
<script src="extjs/adapter/ext/ext-base.js"></script>
<script src="extjs/ext-all-debug.js"></script>
<script>
Ext.BLANK_IMAGE_URL = 'extjs/resources/images/default/s.gif';
// Create an end-to-end Store (ArrayStore)
// our sample data
// an array of arrays - the format for ArrayReader
var arrayData = [
['Ryan Morris', 'NY'],
['Tim Lot', 'MD'],
['Steve Shanigan', 'WA']
];
// create a new Record Constructor "myRecord"
// not the same as "new Record"
// acts as a template for mapping your data fields
var myRecord = Ext.data.Record.create([
{ // each of these object literals are "Ext.data.Field" configs
name: 'name', // field name
mapping: 1 // maps to first value in the data array
},
{
name: 'state',
mapping: 2
}
]);
// instantiate an ArrayReader with "myRecord" as a Record template
// this takes the Mapping configuration from above
// the reader will make a new instance of "myRecord" for each Record in the data
var arrayReader = new Ext.data.ArrayReader({}, myRecord);
// the proxy here is what will load your unformatted data from memory
var memoryProxy = new Ext.data.MemoryProxy(arrayData);
var myStore = new Ext.data.Store({
reader: arrayReader,
proxy: memoryProxy
});
// the above is equivalent to:
var myStore = new Ext.data.ArrayStore({
data: arrayData,
fields: ['name', 'state']
});
// "fields" is as the ArrayStore expects. This is also valid for array store:
var myStore = new Ext.data.ArrayStore({
data: arrayData,
fields : [ 'name', { name : 'state', mapping : 2} ]
});
Ext.onReady(function () {
console.log(myStore);
});
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>