Ext读取Json数据

先写个Json数据吧

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--> 1 ExpandedBlockStart.gif ContractedBlock.gif {"result": [
2ExpandedSubBlockStart.gifContractedSubBlock.gif    {"username""kejiangwei""password":"123""email":"kejiangwei@163.com"},
3ExpandedSubBlockStart.gifContractedSubBlock.gif    {"username""kejiangwei""password":"123""email":"kejiangwei@163.com"},
4ExpandedSubBlockStart.gifContractedSubBlock.gif    {"username""kejiangwei""password":"123""email":"kejiangwei@163.com"},
5ExpandedSubBlockStart.gifContractedSubBlock.gif    {"username""kejiangwei""password":"123""email":"kejiangwei@163.com"},
6ExpandedSubBlockStart.gifContractedSubBlock.gif    {"username""kejiangwei""password":"123""email":"kejiangwei@163.com"},
7ExpandedSubBlockStart.gifContractedSubBlock.gif    {"username""kejiangwei""password":"123""email":"kejiangwei@163.com"}
8], "totalCount":6}

用OO的思想去写JS
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->   1 ExpandedBlockStart.gif ContractedBlock.gif TestGrid  =   function (config)  {
  2ExpandedSubBlockStart.gifContractedSubBlock.gif    config = config || {};
  3    
  4    this.cm = new Ext.grid.ColumnModel([
  5ExpandedSubBlockStart.gifContractedSubBlock.gif        {
  6            header: 'UserName',
  7            dataIndex: 'username',
  8            width    : 80
  9ExpandedSubBlockStart.gifContractedSubBlock.gif        }
{
 10            header: 'Password',
 11            dataIndex: 'password',
 12            width: 80
 13ExpandedSubBlockStart.gifContractedSubBlock.gif        }
{
 14            header: 'Email',
 15            dataIndex: 'email',
 16            width: 100
 17        }

 18    ]);
 19    
 20ExpandedSubBlockStart.gifContractedSubBlock.gif    this.reader = new Ext.data.JsonReader({
 21        root    : 'result',
 22        totalProperty    : 'totalCount',
 23        fields    : [
 24ExpandedSubBlockStart.gifContractedSubBlock.gif            {name: 'username'},
 25ExpandedSubBlockStart.gifContractedSubBlock.gif            {name: 'password'},
 26ExpandedSubBlockStart.gifContractedSubBlock.gif            {name: 'email'}
 27        ]
 28    }
);
 29    
 30    
 31ExpandedSubBlockStart.gifContractedSubBlock.gif    this.store = new Ext.data.Store({
 32        url: 'data.json',
 33//        proxy: new Ext.data.MemoryProxy({url: 'data.json'}),
 34        reader:this.reader
 35    }
);
 36    
 37    this.store.load();
 38    
 39//    this.data = [
 40//        ["kejiangwei","123","kejiangwei@163.com"]
 41//    ];
 42//    this.store = new Ext.data.ArrayStore({
 43//        fields    : [
 44//            {name: 'username'},
 45//            {name: 'password'},
 46//            {name: 'email'}
 47//        ]
 48//    });
 49//    
 50//    this.store.loadData(this.data);
 51
 52//     var cm = new Ext.grid.ColumnModel([
 53//        {
 54//            header: 'UserName',
 55//            dataIndex: 'username',
 56//            width    : 80
 57//        }, {
 58//            header: 'Password',
 59//            dataIndex: 'password',
 60//            width: 80
 61//        }, {
 62//            header: 'Email',
 63//            dataIndex: 'email',
 64//            width: 100
 65//        }
 66//    ]);
 67//    
 68//    var reader = new Ext.data.JsonReader({
 69//        root    : 'result',
 70//        totalProperty    : 'totalCount',
 71//        fields    : [
 72//            {name: 'username'},
 73//            {name: 'password'},
 74//            {name: 'email'}
 75//        ]
 76//    });
 77//    
 78//    
 79//    var store = new Ext.data.Store({
 80//        url: 'data.json',
 81////        proxy: new Ext.data.MemoryProxy({url: 'data.json'}),
 82//        reader:reader
 83//    });
 84//    
 85//    store.load();
 86    
 87ExpandedSubBlockStart.gifContractedSubBlock.gif    Ext.applyIf(config, {
 88        width    : 300,
 89        height    : 250//,
//用this的话这些就不用配了上面已经配好了 这样 简单 好 
 90//        store    : store,
 91//        cm    : cm
 92    }
);
 93    
 94    TestGrid.superclass.constructor.call(this, config);
 95}

 96 ExpandedBlockStart.gifContractedBlock.gifExt.extend(TestGrid, Ext.grid.GridPanel,  {} );
 97
 98 ExpandedBlockStart.gifContractedBlock.gifExt.onReady( function () {
 99    
100    var test = new TestGrid();
101    test.render("div_main");
102
103}
);
用Var 和用this的不同。在上面有标注了  也有例子对比

在写个测试页吧
ContractedBlock.gif ExpandedBlockStart.gif Code
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  
<head>
    
<title>test.html</title>
    
    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    
<meta http-equiv="description" content="this is my page">
    
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
    
<link rel="stylesheet" type="text/css" href="../extjs/resources/css/ext-all.css">
    
<script type="text/javascript" src="../extjs/adapter/ext/ext-base.js"></script>
    
<script type="text/javascript" src="../extjs/ext-all.js"></script>
    
    
<script type="text/javascript" src="TestGrid.js"></script>

  
</head>
  
  
<body>
    
<div id="div_main"></div>
  
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值