【问题标题】:Sencha Offline ProxySencha 离线代理
【发布时间】:2017-12-21 14:14:47
【问题描述】:

当 json 收到 100 条记录时,Sencha 离线代理面临问题 离线代理仅添加 50 条记录添加在商店这里是我的简单代码 response.responseText [我的 ajax 响应],它返回记录集

           var data = Ext.decode(response.responseText);
              for (var c=0; c < data.length; c++){
                   console.log(c);
                    var itemrecord  = Ext.create('Inertia.model.InstallingCompany');
                    itemrecord.set(data[c]);
                    Ext.getStore('InstallingCompanies-offline').add(itemrecord);
               }
            console.log(c);
            console.log(Ext.getStore('InstallingCompanies-offline').data.length);

【问题讨论】:

    标签: extjs proxy offline


    【解决方案1】:

    为此,您可以使用store 的直接store.loadData() 方法。

    在这个FIDDLE中,我使用gridpanelExt.data.Store创建了一个演示。我希望这个FIDDLE 能帮助您或指导您实现您的要求。

    代码片段

     Ext.define('ForumThread', {
         extend: 'Ext.data.Model',
         fields: [
             'title', 'forumtitle', 'forumid', 'username', {
                 name: 'replycount',
                 type: 'int'
             }, {
                 name: 'lastpost',
                 mapping: 'lastpost',
                 type: 'date',
                 dateFormat: 'timestamp'
             },
             'lastposter', 'excerpt', 'threadid'
         ],
         idProperty: 'threadid'
     });
    
     Ext.create('Ext.data.Store', {
         storeId: 'topicsStore',
         model: 'ForumThread'
     });
    
     function renderTopic(value, p, record) {
         return Ext.String.format(
             '<a href="http://sencha.com/forum/showthread.php?t={2}" target="_blank">{0}</a>',
             value,
             record.data.forumtitle,
             record.getId(),
             record.data.forumid
         );
     }
    
     Ext.create('Ext.grid.Panel', {
         height: window.innerHeight,
         title: 'Example of Store loadData() with GRID and Ajax Request',
         renderTo: Ext.getBody(),
         store: Ext.data.StoreManager.lookup('topicsStore'),
         loadMask: true,
         columns: [{
             xtype: 'rownumberer',
             width: 35,
             sortable: false
         }, {
             tdCls: 'x-grid-cell-topic',
             text: "Topic",
             dataIndex: 'title',
             flex: 1,
             renderer: renderTopic,
             sortable: true,
             groupable: false,
             cellWrap: true
         }, {
             text: "Author",
             dataIndex: 'username',
             flex: 0.5,
             sortable: true,
             groupable: false
         }, {
             text: "Replies",
             dataIndex: 'replycount',
             align: 'center',
             width: 90,
             sortable: false
         }, {
             id: 'last',
             text: "Last Post",
             dataIndex: 'lastpost',
             flex: 0.5,
             renderer: Ext.util.Format.dateRenderer('n/j/Y g:i A'),
             sortable: true,
             groupable: false
         }],
         listeners: {
             afterrender: function (cmp) {
                 var store = Ext.data.StoreManager.lookup('topicsStore'),
                     store1;
                 cmp.getEl().mask('Please wait..!');
                 Ext.Ajax.request({
                     url: 'topics.json',
                     success: function (data) {
                         var response = Ext.decode(data.responseText);
                         store.loadData(response.topics);
                         cmp.getEl().unmask();
    
                         //Add data using store.add() method in Store
                         store1 = Ext.create('Ext.data.Store', {
                             model: 'ForumThread'
                         });
                         response.topics.forEach(function (item) {
                             store1.add(item);
                         })
                         console.log(`total count of store1 data is ${store1.getCount()}`);
                     }
                 });
             }
         }
     });
    

    【讨论】:

      猜你喜欢
      • 2012-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-23
      • 2013-06-02
      • 2010-11-18
      • 1970-01-01
      • 2013-11-17
      相关资源
      最近更新 更多