ExtJs之Ext.XTemplate:模板成员函数

简介:
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
<! 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 >

  

目录
相关文章
|
Web App开发 JavaScript 容器