【问题标题】:ExtJS4 - Proxy, Store, Model, Autoload - whats the magic?ExtJS4 - 代理、存储、模型、自动加载 - 有什么魔力?
【发布时间】:2012-07-10 08:04:54
【问题描述】:

我的模型上定义了一个代理。

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

store.autoLoad: 真的不行

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

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

这是预期的行为吗?

  1. 这不就是自动加载的目的吗?
  2. 是否只有在商店中定义了代理时才有效?

代码:

model/MyThing.js

Ext.define('MyApp.model.MyThing', {

  extend: 'Ext.data.Model',

  fields: ['id', 'reference'],

  proxy:
  {
    type: 'ajax',
    url: 'MyThings'
  }
});

store/MyThings.js

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

【问题讨论】:

  • 确保您拥有autoLoad 而不是autoload。一旦你启动应用程序,它应该会自动加载商店。

标签: model proxy extjs4 store


【解决方案1】:

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

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

我将您的代码添加到我的应用中并获得了预期的结果,所以它应该可以工作。

更新:

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

【讨论】:

  • 是的,我可以看到它也有用途
【解决方案2】:

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

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

最佳实践是订阅 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);
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    • 2023-03-29
    • 2016-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多