-
Notifications
You must be signed in to change notification settings - Fork 0
/
example2.html
169 lines (167 loc) · 3.94 KB
/
example2.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>Looping over arrays [Ext JS Templating Magic]</title>
<script src="ext-3.3.1/adapter/ext/ext-base.js"></script>
<script src="ext-3.3.1/ext-all.js"></script>
<script src="examples.js"></script>
<link rel="stylesheet" type="text/css" href="ext-3.3.1/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="examples.css" />
<script>
Ext.onReady(function() {
var order = {
"Customer":{
"Id":"BOLID",
"CompanyName":"Bólido Comidas preparadas",
"ContactName":"Martín Sommer",
"ContactTitle":"Owner",
"Address":"C/ Araquil, 67",
"City":"Madrid",
"PostalCode":"28023",
"Country":"Spain",
"Phone":"(91) 555 22 82",
"Fax":"(91) 555 91 99"
},
"CustomerOrders":[
{
"Order":{
"Id":10326,
"CustomerId":"BOLID",
"EmployeeId":4,
"OrderDate":"\/Date(844898400000+0000)\/",
"RequiredDate":"\/Date(847321200000+0000)\/",
"ShippedDate":"\/Date(845244000000+0000)\/",
"ShipVia":2,
"Freight":77.92,
"ShipName":"Bólido Comidas preparadas",
"ShipAddress":"C/ Araquil, 67",
"ShipCity":"Madrid",
"ShipPostalCode":"28023",
"ShipCountry":"Spain"
},
"OrderDetails":[
{
"OrderId":10326,
"ProductId":4,
"UnitPrice":17.6,
"Quantity":24,
"Discount":0
},
{
"OrderId":10326,
"ProductId":57,
"UnitPrice":15.6,
"Quantity":16,
"Discount":0
},
{
"OrderId":10326,
"ProductId":75,
"UnitPrice":6.2,
"Quantity":50,
"Discount":0
}
]
},
{
"Order":{
"Id":10801,
"CustomerId":"BOLID",
"EmployeeId":4,
"OrderDate":"\/Date(883350000000+0000)\/",
"RequiredDate":"\/Date(885769200000+0000)\/",
"ShippedDate":"\/Date(883522800000+0000)\/",
"ShipVia":2,
"Freight":97.09,
"ShipName":"Bólido Comidas preparadas",
"ShipAddress":"C/ Araquil, 67",
"ShipCity":"Madrid",
"ShipPostalCode":"28023",
"ShipCountry":"Spain"
},
"OrderDetails":[
{
"OrderId":10801,
"ProductId":17,
"UnitPrice":39,
"Quantity":40,
"Discount":0.25
},
{
"OrderId":10801,
"ProductId":29,
"UnitPrice":123.79,
"Quantity":20,
"Discount":0.25
}
]
},
{
"Order":{
"Id":10970,
"CustomerId":"BOLID",
"EmployeeId":9,
"OrderDate":"\/Date(890694000000+0000)\/",
"RequiredDate":"\/Date(891900000000+0000)\/",
"ShippedDate":"\/Date(893368800000+0000)\/",
"ShipVia":1,
"Freight":16.16,
"ShipName":"Bólido Comidas preparadas",
"ShipAddress":"C/ Araquil, 67",
"ShipCity":"Madrid",
"ShipPostalCode":"28023",
"ShipCountry":"Spain"
},
"OrderDetails":[
{
"OrderId":10970,
"ProductId":52,
"UnitPrice":7,
"Quantity":40,
"Discount":0.2
}
]
}
]
};
var template = new Ext.XTemplate(
'<table class="order">',
'<thead>',
'<tr>',
'<th>No.</th>',
'<th>Product</th>',
'<th>Unit Price</th>',
'<th>Quantity</th>',
'</tr>',
'</thead>',
'<tbody>',
'<tpl for=".">',
'<tr>',
'<td>{#}.</td>',
'<td>Product ID <b>{ProductId}</b></td>',
'<td>{UnitPrice:usMoney}</td>',
'<td>{Quantity}</td>',
'</tr>',
'</tpl>',
'</tbody>',
'</table>'
);
// apply the first OrderDetails object to the template
template.append('content', order.CustomerOrders[0].OrderDetails);
});
</script>
</head>
<body id="example2">
<ul id="page-nav">
<li><a rel="index" href="#">index</a></li>
<li><a rel="prev" href="#">←</a></li>
<li><a rel="next" href="#">→</a></li>
</ul>
<h1><a rel="source" href="#">view source</a>Looping over arrays</h1>
<div id="content"></div>
<div id="footer">
Stefan Gehrig, 2011, to accompany the article "Ext JS templating magic" in <a href="http://jsmag.com"><jsmag></a> 05/2011
</div>
</body>
</html>