ExtJS4 - 代理,存储,模型,自动加载 - 什么是神奇的?

时间:2012-07-10 19:08:57

标签: model proxy extjs4 store

我在我的模型上定义了代理。

我有一个定义指向模型的商店,没有代理,因为我希望它使用模型上定义的那个。

store.autoLoad:true无效

我必须从我的控制器显式调用

var store = this.getMyStore();
store.load();

这是预期的行为吗?

  1. 这不是autoload的用途吗?
  2. 只有在商店中定义代理时才会起作用吗?
  3. 代码:

    模型/ MyThing.js

    Ext.define('MyApp.model.MyThing', {
    
      extend: 'Ext.data.Model',
    
      fields: ['id', 'reference'],
    
      proxy:
      {
        type: 'ajax',
        url: 'MyThings'
      }
    });
    

    商品/ MyThings.js

    Ext.define('MyApp.store.MyThings', {
      extend: 'Ext.data.Store',
      autoLoad: true,
      autoSync: false,
      model: 'MyApp.model.MyThing'
    });
    

2 个答案:

答案 0 :(得分:2)

您没有展示如何创建商店。 您应该在调用时看到FireBug中的HTTP GET请求(假设您正在使用FireFox并拥有它):

Ext.create('MyApp.store.MyThings');

我将您的代码添加到我的应用中并获得了预期的结果,因此它应该正常运行。

<强>更新

根据您自己发布的答案,您可以将该配置对象提供为autoLoad(而不是autoLoad: true)以获得相同的功能,而无需显式调用store.load()

答案 1 :(得分:0)

实际上,这有点像新手。我是一个热切的海狸。

在完成加载之前,我正在查看商店(因为它是异步的)。

最佳做法是订阅load()函数的回调,然后做一些事情......

store.load({
    scope   : this,
    callback: function(records, operation, success) {
        //the operation object contains all of the details of the load operation
        console.log(records);
    }
});