简体   繁体   English

存储代理Extraparams检索记录

[英]Store proxy extraparams retrieve record

I need to send some data to a store proxy and instead of reloading the store I just want to get that record. 我需要将一些数据发送到商店代理,而不是重新加载商店,我只想获取该记录。 Can this be done? 能做到吗?

 var newRecord =  documentStore.getProxy().extraParams = {id:element.data.id};

Something like above which of course doesn't work 像上面这样的东西当然不起作用

If that data/record is already loaded in store then you can get it using store.findRecord() or store.getById() methods. 如果该数据/记录已经加载到store中,则可以使用store.findRecord()store.getById()方法获取它。

But if you want record which is not loaded/available in store, then you will need to reload your store with required values(filter). 但是,如果要记录商店中未加载/不可用的记录,则需要使用所需的值(过滤器)重新加载商店。

Update : 更新:

Well, you can capture the itemclick or cellclick event for first grid, and load the second grid store with passing required filter parameters OR you can create AJAX request, get the response and build the record and add it to other store. 好了,您可以捕获第一个网格的itemclickcellclick事件,并通过传递必需的过滤器参数来加载第二个网格存储,也可以创建AJAX请求,获取响应并构建记录并将其添加到其他存储中。

If you have a proxy on your Model you can use the static "load" method, ie if you have a model "Contact" you would do this: 如果您在模型上具有代理,则可以使用静态“加载”方法,即,如果您有模型“ Contact”,则可以这样做:

Contact.load("ID_VALUE", {
     scope: this,
     callback: function (record, operation, success) {
     }
});

It sounds like you are trying to select a record from one list of items, retrieve additional data for that selected item, and then have that item be added to an existing store. 听起来您正在尝试从一个项目列表中选择一条记录,为该选定项目检索其他数据,然后将该项目添加到现有商店中。

Please correct me if this is wrong. 如果这是错误的,请纠正我。 But, going on this assumption, you could have a load method on a Model as bhutten has suggested. 但是,按照这个假设,您可以按照bhutten的建议在模型上有一个加载方法。 On the return of the model (ie callback), you would then add that Model to the Store via the Ext.data.Store.add(model) method. 在返回模型(即回调)时,您可以通过Ext.data.Store.add(model)方法将该模型添加到Store中。 This would add the record to the data store without reloading all of the data in the store. 这会将记录添加到数据存储中,而无需重新加载存储中的所有数据。

Perhaps a more elegant approach could be creating your own store (ie myApp.store.MyStore) that extends the Ext.data.Store. 也许更优雅的方法是创建自己的扩展Ext.data.Store的商店(即myApp.store.MyStore)。 Then, create your own method that accepts an identifier (or multiple identifiers) that could load models to the Store without reloading the entire store. 然后,创建您自己的方法,该方法接受一个(或多个)标识符,该标识符可以将模型加载到商店中,而无需重新加载整个商店。

Ext.define('MyApp.store.MyStore' {
  extend: 'Ext.data.Store',
  requires: 'Ext.data.reader.Json',
  model: 'MyApp.model.MyModel',
  loadMyModel: function (id) {
    Ext.Ajax.request({
      url: 'someurl',
      params: {id: id},
      success: function (resp) {
        var myModel = null; // parse response into MyModel
        this.add(myModel);
      },
      scope: this
    });
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM