Extjs 4 获取尚未从远程存储加载的记录索引



>例如,我有一个存储,有 3000 条记录,我的 pageSize 是 250。我还有一个来自其中一条记录的唯一值(假设product_id = 2333),但该记录尚未加载,因此store.findRecord("product_id", product_id)将返回 null。

我的问题是,如何获取尚未加载的记录的索引,以便在获取索引后加载正确的页面?

您应该使用存储的 onload 方法:

store.on('load',function(component,records){
   //here all the records are loaded, so:
   component.findRecord('prop',value)//will return your record
  //here you can load the page you need
},this,{single:true});

如果记录尚不存在,则找不到该记录,唯一的方法是等到加载存储。

属性single:true传递为选项仅指示每次在加载侦听器上设置此函数时都会执行一次。

请注意,如果省略存储负载将执行附加到该负载的所有侦听器。

如果你想要一个完美的方法来做到这一点:

view.mask('loading the page...');
store.on('load',function(component,records){
       component.findRecord('prop',value)//will return your record
      //here you can load the page you need
      page.load(); //simply example
      view.unmask();
},this,{single:true});
store.load();

view.mask('loading the page...');
    store.load(function(records){
           store.findRecord('prop',value)//will return your record
          //here you can load the page you need
          page.load(); //simply example
          view.unmask();
    });

最新更新