如果我手动加载存储,ExtJS TreeStore为空

时间:2014-11-08 18:41:53

标签: extjs

模型

Ext.define('MyDesktop.model.mail.MailFoldersModel', {
    extend: 'Ext.data.Model',

    requires: [
        'Ext.data.field.String'
    ],

    fields: [
        {
            type: 'string',
            name: 'id'
        },
        {
            type: 'string',
            name: 'idParent'
        },
        {
            type: 'string',
            name: 'text'
        }
    ]
});

我的TreeStore

Ext.define('MyDesktop.store.mail.MailFoldersStore', {
  extend: 'Ext.data.TreeStore',

  requires: [
    'MyDesktop.model.mail.MailFoldersModel'
  ],

  constructor: function(cfg) {
    var me = this;
    cfg = cfg || {};
    me.callParent([Ext.apply({
      storeId: 'MailFoldersStore',
      model: 'MyDesktop.model.mail.MailFoldersModel',
      autoLoad: true,
      proxy: {
        type: 'ajax',
        url: 'http://url/mail/folders',
        reader: {
          type: 'json',
          rootProperty: 'items',
          successProperty: 'success'
        }
      },
      root: {
        text: 'root',
        iconCls: 'mail-folders-owner'
      }
    }, cfg)]);
  }
});

存储已自动加载,一切正常,存储包含11条记录。

var MailFoldersStore = Ext.create('MyDesktop.store.mail.MailFoldersStore', {
  storeId: 'MailFoldersStore'
});

如果我将autoLoad设置为false并尝试手动加载 - store为空,则为0记录。

var MailFoldersStore = Ext.create('MyDesktop.store.mail.MailFoldersStore', {
  storeId: 'MailFoldersStore'
});
MailFoldersStore.load({
  callback : function(records, operation, success) {
    console.log(records);
  }
});

这种行为可能是什么原因?

1 个答案:

答案 0 :(得分:1)

我也有同样的问题。我正在使用Extjs 5.1。谷歌搜索后,我找到了一个复杂的解决方案,需要我们修改框架。

如果可以帮到您,请参阅以下链接。

http://www.sencha.com/forum/showthread.php?154823-listeners-quot-exception-quot-in-proxy.ajax-on-TreeStore-do-not-work