隨筆-9  評論-168  文章-266  trackbacks-0
          1) // create 最基本建立Record和Store的方法
          var myStore = new Ext.data.Store();
          var TopicRecord = Ext.data.Record.create([
                  {name: 'title', mapping: 'topic_title'},
                  {name: 'author', mapping: 'username'},
                  {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
                  {name: 'lastPost', mapping: 'post_time', type: 'date'},
                  {name: 'lastPoster', mapping: 'user2'},
                  {name: 'excerpt', mapping: 'post_text'}
          ]); // 列表影射,columnModel
          var myNewRecord = new TopicRecord({
                  title: 'Do my job please',
                  author: 'noobie',
                  totalPosts: 1,
                  lastPost: new Date(),
                  lastPoster: 'Animal',
                  excerpt: 'No way dude!'
          }); // 實(shí)際的一條記錄
          myStore.add(myNewRecord);

          2) // 這種方法也可以構(gòu)建一個(gè)store
          var store = new Ext.data.SimpleStore({
                  fields: ['abbr', 'state', 'nick'], // 一定要有這個(gè),如果放在grid中,與column的dataIndex屬性值對應(yīng)
                  data : [
                  ['AL', 'Alabama', 'The Heart of Dixie'],
                  ['AK', 'Alaska', 'The Land of the Midnight Sun'],
                  ['IN', 'Indiana', 'The Hospitality State']
                  ]
          });

          3) 還有一個(gè)種方法,用ArrayReader,數(shù)據(jù)源是js二維數(shù)組,用SimpleStore
          var store = new Ext.data.SimpleStore({
                  /*
                  數(shù)據(jù)源:[ [1, 'AL', '0.1', 'The Heart of Dixie', '6', new Date()] ]
                  ArrayReader中, ajax會返回一個(gè)數(shù)據(jù)源給ArrayReader,
                          fields數(shù)組與數(shù)據(jù)源的序列的順序要相同
                  */
                  fields: ['pid', 'company', 'price', 'change', 'pctChange', 'lastChange'],
                  url: 't2.php',
                  reader: new Ext.data.ArrayReader(
                          {id: 0},
                          /*
                          id 的取值應(yīng)為下面的mapping的值,如果在下面沒有出現(xiàn),則取數(shù)據(jù)源的0序列
                          ,recordid可通過store.getById(recordid) 取得相應(yīng)的 Record
                          當(dāng)有 id 這個(gè)屬性設(shè)置的時(shí)候,如果id值為2,就表示用price作recordid
                          , 如果 name 的值與數(shù)據(jù)源的序列的名稱相同,就可以不指定mapping
                          */
                          [{name:'company',mapping: 1}, {name:'price',mapping: 2}, {name:'change',mapping: 3}, {name:'pctChange',mapping: 4}, {name:'lastChange',mapping: 5}]
                          )
          });
          // 因?yàn)槭褂胾rl會觸發(fā)ajax, 是異步方式,如果是要ajax讀取數(shù)據(jù)后馬上觸發(fā)事件,
          // 必須添加load事件的監(jiān)聽
          store.addListener('load', function(st, rds, opts) {
                  // st 是當(dāng)前的store, rds是讀到的Record[], opts是store的配置
                  //alert(rds.getTotalCount());
                  nextstore.removeAll(); //先清除另一個(gè)store的內(nèi)容
                  nextstore.add(rds); // 給另一個(gè)store添加這些records
                  //for( var c=0; c<rds.length; c++ ) store.addSorted(rds[c]);
          });
          store.load();

          4) 還有一個(gè)種方法,用XmlReader,數(shù)據(jù)源是xml, 只能用Ext.data.Store,不能用SimpleStore
          就因?yàn)镾impleStore,害我搞了n久才發(fā)現(xiàn)只能用Store
          先看數(shù)據(jù)源:
          <?xml?>
          <dataset>
          <results>2</results>
          <row>
             <id>1</id>
             <name>Bill</name>
             <occupation>Gardener</occupation>
          </row>
          <row>
             <id>2</id>
             <name>Ben</name>
             <occupation>Horticulturalist</occupation>
          </row>
          </dataset>
          js:
          var store = new Ext.data.Store({
                  fields: ['id', 'name', 'occupation'],
                  url: 't2.php',
                  reader: new Ext.data.XmlReader(
                          {
                          record: "row", // xml中每行數(shù)據(jù)的內(nèi)容
                          totalRecords: "results", // xml中的results節(jié)點(diǎn),表時(shí)記錄數(shù) (option)
                          id: 'id'
                          // 每行數(shù)據(jù)的素引,xml中是row標(biāo)簽的子節(jié)點(diǎn), 作recordid, (option),
                          // 如果id列在數(shù)據(jù)源中的值有重復(fù),就只會顯前面的列,后面的放棄.
                          },
                          /*
                          id 的取值應(yīng)為下面的mapping的值,如果在下面沒有出現(xiàn),則取數(shù)據(jù)源的0序列
                          當(dāng)有 id 這個(gè)屬性設(shè)置的時(shí)候,如果id值為2,就表示用price作recordid
                          下面的mapping,是定義的素引與xml中的節(jié)點(diǎn)對應(yīng)
                          , 如果 name 的值與數(shù)據(jù)源的序列的名稱相同,就可以不指定mapping
                          */
                          [{name:'name',mapping: 'name'}, {name:'occupation'} ]
                          // 這里也可寫成 ['id', 'name', 'occupation']
                  )
          });
          // 因?yàn)槭褂胾rl會觸發(fā)ajax, 是異步方式,如果是要ajax讀取數(shù)據(jù)后馬上觸發(fā)事件,
          // 必須添加load事件的監(jiān)聽
          store.addListener('load', function(st, rds, opts) {
                  // st 是當(dāng)前的store, rds是讀到的Record[], opts是store的配置
                  //alert(rds.getTotalCount());
                  nextstore.removeAll(); //先清除另一個(gè)store的內(nèi)容
                  nextstore.add(rds); // 給另一個(gè)store添加這些records
                  //for( var c=0; c<rds.length; c++ ) store.addSorted(rds[c]);
          });
          store.load();

                                                               ----------------http://cwq.jsp-tech.cn/2008/04/extjsrecordstore.html
          posted on 2008-09-18 15:34 紫蝶∏飛揚(yáng)↗ 閱讀(5101) 評論(2)  編輯  收藏 所屬分類: EXTJS

          評論:
          # re: [轉(zhuǎn)]Ext.data.Store Ext.data.Record XmlReader SimpleStore 2008-10-09 18:43 | cwq
          http://cwq.jsp-tech.cn/2008/04/extjsrecordstore.html
          麻煩鏈接加上A標(biāo)簽可以嗎,

          可以交換友鏈嗎?  回復(fù)  更多評論
            
          # re: [轉(zhuǎn)]Ext.data.Store Ext.data.Record XmlReader SimpleStore 2010-04-16 13:53 | Stan
          I'm interested in your posts.
          I want you to translate this post into English.
          Can you...?  回復(fù)  更多評論
            
          主站蜘蛛池模板: 秦皇岛市| 康保县| 昔阳县| 仙游县| 灵山县| 类乌齐县| 阿合奇县| 天津市| 海林市| 凤冈县| 军事| 保靖县| 措美县| 香河县| 抚顺市| 理塘县| 陇南市| 正定县| 镇江市| 将乐县| 富阳市| 无为县| 宁海县| 建瓯市| 托克托县| 商丘市| 通州市| 农安县| 礼泉县| 信宜市| 辉县市| 东阿县| 都兰县| 藁城市| 炎陵县| 凌海市| 石首市| 汪清县| 广安市| 乐都县| 运城市|