天天看點

Ext讀取Json資料

先寫個Json資料吧

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--> 1

Ext讀取Json資料
Ext讀取Json資料
Ext讀取Json資料

{"result": [

2

Ext讀取Json資料
Ext讀取Json資料
Ext讀取Json資料

{"username": "kejiangwei", "password":"123", "email":"[email protected]"},

3

Ext讀取Json資料
Ext讀取Json資料
Ext讀取Json資料

{"username": "kejiangwei", "password":"123", "email":"[email protected]"},

4

Ext讀取Json資料
Ext讀取Json資料
Ext讀取Json資料

{"username": "kejiangwei", "password":"123", "email":"[email protected]"},

5

Ext讀取Json資料
Ext讀取Json資料
Ext讀取Json資料

{"username": "kejiangwei", "password":"123", "email":"[email protected]"},

6

Ext讀取Json資料
Ext讀取Json資料
Ext讀取Json資料

{"username": "kejiangwei", "password":"123", "email":"[email protected]"},

7

Ext讀取Json資料
Ext讀取Json資料
Ext讀取Json資料

{"username": "kejiangwei", "password":"123", "email":"[email protected]"}

8

Ext讀取Json資料

], "totalCount":6}

用OO的思想去寫JS

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->   1

Ext讀取Json資料
Ext讀取Json資料

TestGrid  =   function (config) 

Ext讀取Json資料

{

  2

Ext讀取Json資料
Ext讀取Json資料

    config = config || 

Ext讀取Json資料

{};

  3

Ext讀取Json資料

  4

Ext讀取Json資料

    this.cm = new Ext.grid.ColumnModel([

  5

Ext讀取Json資料
Ext讀取Json資料
Ext讀取Json資料

{

  6

Ext讀取Json資料

            header: 'UserName',

  7

Ext讀取Json資料

            dataIndex: 'username',

  8

Ext讀取Json資料

            width    : 80

  9

Ext讀取Json資料
Ext讀取Json資料

        }, 

Ext讀取Json資料

{

 10

Ext讀取Json資料

            header: 'Password',

 11

Ext讀取Json資料

            dataIndex: 'password',

 12

Ext讀取Json資料

            width: 80

 13

Ext讀取Json資料
Ext讀取Json資料

        }, 

Ext讀取Json資料

{

 14

Ext讀取Json資料

            header: 'Email',

 15

Ext讀取Json資料

            dataIndex: 'email',

 16

Ext讀取Json資料

            width: 100

 17

Ext讀取Json資料

        }

 18

Ext讀取Json資料

    ]);

 19

Ext讀取Json資料

 20

Ext讀取Json資料
Ext讀取Json資料

    this.reader = new Ext.data.JsonReader(

Ext讀取Json資料

{

 21

Ext讀取Json資料

        root    : 'result',

 22

Ext讀取Json資料

        totalProperty    : 'totalCount',

 23

Ext讀取Json資料

        fields    : [

 24

Ext讀取Json資料
Ext讀取Json資料
Ext讀取Json資料

{name: 'username'},

 25

Ext讀取Json資料
Ext讀取Json資料
Ext讀取Json資料

{name: 'password'},

 26

Ext讀取Json資料
Ext讀取Json資料
Ext讀取Json資料

{name: 'email'}

 27

Ext讀取Json資料

        ]

 28

Ext讀取Json資料

    });

 29

Ext讀取Json資料

 30

Ext讀取Json資料

 31

Ext讀取Json資料
Ext讀取Json資料

    this.store = new Ext.data.Store(

Ext讀取Json資料

{

 32

Ext讀取Json資料

        url: 'data.json',

 33

Ext讀取Json資料

//        proxy: new Ext.data.MemoryProxy({url: 'data.json'}),

 34

Ext讀取Json資料

        reader:this.reader

 35

Ext讀取Json資料

    });

 36

Ext讀取Json資料

 37

Ext讀取Json資料

    this.store.load();

 38

Ext讀取Json資料

 39

Ext讀取Json資料

//    this.data = [

 40

Ext讀取Json資料

//        ["kejiangwei","123","[email protected]"]

 41

Ext讀取Json資料

//    ];

 42

Ext讀取Json資料

//    this.store = new Ext.data.ArrayStore({

 43

Ext讀取Json資料

//        fields    : [

 44

Ext讀取Json資料

//            {name: 'username'},

 45

Ext讀取Json資料

//            {name: 'password'},

 46

Ext讀取Json資料

//            {name: 'email'}

 47

Ext讀取Json資料

//        ]

 48

Ext讀取Json資料

//    });

 49

Ext讀取Json資料

//    

 50

Ext讀取Json資料

//    this.store.loadData(this.data);

 51

Ext讀取Json資料

 52

Ext讀取Json資料

//     var cm = new Ext.grid.ColumnModel([

 53

Ext讀取Json資料

//        {

 54

Ext讀取Json資料

//            header: 'UserName',

 55

Ext讀取Json資料

//            dataIndex: 'username',

 56

Ext讀取Json資料

//            width    : 80

 57

Ext讀取Json資料

//        }, {

 58

Ext讀取Json資料

//            header: 'Password',

 59

Ext讀取Json資料

//            dataIndex: 'password',

 60

Ext讀取Json資料

//            width: 80

 61

Ext讀取Json資料

//        }, {

 62

Ext讀取Json資料

//            header: 'Email',

 63

Ext讀取Json資料

//            dataIndex: 'email',

 64

Ext讀取Json資料

//            width: 100

 65

Ext讀取Json資料

//        }

 66

Ext讀取Json資料

//    ]);

 67

Ext讀取Json資料

//    

 68

Ext讀取Json資料

//    var reader = new Ext.data.JsonReader({

 69

Ext讀取Json資料

//        root    : 'result',

 70

Ext讀取Json資料

//        totalProperty    : 'totalCount',

 71

Ext讀取Json資料

//        fields    : [

 72

Ext讀取Json資料

//            {name: 'username'},

 73

Ext讀取Json資料

//            {name: 'password'},

 74

Ext讀取Json資料

//            {name: 'email'}

 75

Ext讀取Json資料

//        ]

 76

Ext讀取Json資料

//    });

 77

Ext讀取Json資料

//    

 78

Ext讀取Json資料

//    

 79

Ext讀取Json資料

//    var store = new Ext.data.Store({

 80

Ext讀取Json資料

//        url: 'data.json',

 81

Ext讀取Json資料

////        proxy: new Ext.data.MemoryProxy({url: 'data.json'}),

 82

Ext讀取Json資料

//        reader:reader

 83

Ext讀取Json資料

//    });

 84

Ext讀取Json資料

//    

 85

Ext讀取Json資料

//    store.load();

 86

Ext讀取Json資料

 87

Ext讀取Json資料
Ext讀取Json資料

    Ext.applyIf(config, 

Ext讀取Json資料

{

 88

Ext讀取Json資料

        width    : 300,

 89

Ext讀取Json資料

        height    : 250//,

//用this的話這些就不用配了上面已經配好了 這樣 簡單 好 

 90

Ext讀取Json資料

//        store    : store,

 91

Ext讀取Json資料

//        cm    : cm

 92

Ext讀取Json資料

    });

 93

Ext讀取Json資料

 94

Ext讀取Json資料

    TestGrid.superclass.constructor.call(this, config);

 95

Ext讀取Json資料

}

 96

Ext讀取Json資料
Ext讀取Json資料

Ext.extend(TestGrid, Ext.grid.GridPanel, 

Ext讀取Json資料

{} );

 97

Ext讀取Json資料

 98

Ext讀取Json資料
Ext讀取Json資料

Ext.onReady( function ()

Ext讀取Json資料

{

 99

Ext讀取Json資料

100

Ext讀取Json資料

    var test = new TestGrid();

101

Ext讀取Json資料

    test.render("div_main");

102

Ext讀取Json資料

103

Ext讀取Json資料

} ); 用Var 和用this的不同。在上面有标注了  也有例子對比

在寫個測試頁吧

Ext讀取Json資料
Ext讀取Json資料

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" target="_blank" rel="external nofollow" >-->

    <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>

繼續閱讀