2.3_advanced_xtemplate_usage

本文演示了如何使用ExtJS XTemplate进行高级模板化的实现,通过实例展示了如何在数据对象中循环遍历并动态添加特定条件的元素。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Ext JS in Action Chapter 02 |Listing 2.3 Advanced XTemplate usage</title>
<link rel="stylesheet" type="text/css" href="./ext3/resources/css/ext-all.css" />
<script type="text/javascript" src="./ext3/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="./ext3/ext-all-debug.js"></script>
<script type="text/javascript">
Ext.BLANK_IMAGE_URL = './ext3/resources/images/default/s.gif';
</script>
<script type="text/javascript">

Ext.onReady(function() {
/**
* The purpose of this example is to demonstrate how to implement an Ext.XTemplate using inline methods. This
* implementation will loop through the cars array inside of each data object provided to the XTemplate. The
* nested if tag for the tpl element will execute the dynamically added isCamry method, which if true, will append
* "(same car)" to the text on screen.
*/
var tplData = [{
color : "#FFE9E9",
name : 'Naomi White',
age : 25,
dob : '03/17/84',
cars : ['Jetta', 'Camry', 'S2000', "M3"]
},{
color : "#E9E9FF",
name : 'John Smith',
age : 20,
dob : '10/20/89',
cars : ['Civic', 'Accord', 'Camry']
}];

var myTpl = new Ext.XTemplate(
'<tpl for=".">',
'<div style="background-color: {color}; margin: 10px;">',
'<b> Name :</b> {name}<br />',
'<b> Age :</b> {age}<br />',
'<b> DOB :</b> {dob}<br />',
'<b> Cars : </b>',
'<tpl for="cars">',
'{.}',
'<tpl if="this.isCamry(values)">',
'<b> (same car)</b>',
'</tpl>',
'{[ (xindex < xcount) ? ", " : "" ]}',
'</tpl>',
'<br />',
'</div>',
'</tpl>',
{
isCamry : function(car) {
return car === 'Camry';
}
}
);
myTpl.compile();

myTpl.append(document.body, tplData);


});
</script></head>
<body>

</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值