<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link rel="stylesheet" type="text/css" href="ExtJs/packages/ext-theme-crisp/build/resources/ext-theme-crisp-all.css"> <script type="text/javascript" src="ExtJs/ext-all.js"></script> <script type="text/javascript" src="ExtJs/bootstrap.js"></script> <script type="text/javascript" src="ExtJs/packages/ext-theme-crisp/build/ext-theme-crisp.js"></script> <script type="text/javascript"> Ext.onReady(function(){ var tpl1 = new Ext.XTemplate( '<table border=1 cellpadding=1 cellspacing=1>', '<tr><td width=90>姓名</td><td width=90>工资</td></tr>', '<tpl for=".">', '<tpl if="this.check(wage)">', '<tr><td>{name}</td><td>{[this.format(values.wage)]}</td></tr>', '</tpl></tpl>', '</table>', { check: function(wage) { if (wage >1000){ return true; }else { return false } }, format: function(wage){ if(wage> 1300){ return '<font color=red>' + wage + '</font>'; }else { return '<font color=blue>' + wage + '</font>'; } } } ); var tplData = [ {name: '张三', wage: 1320}, {name: '郴四', wage: 1200}, {name: '五爷', wage: 1556}, {name: '老炮', wage: 1134}, {name: '学军', wage: 1822} ] tpl1.append('tpl-table1', tplData); }); </script> </head> <body> <div id='tpl-table1'></div> <br> <div id='tpl-table2'></div> </body> </html>