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

时间:2017-02-01 13:11:12

标签: load store record extjs4.2

我有一个商店,例如有3000条记录,而我的pageSize是250.我也有一条记录中的唯一值(比如说product_id = 2333),但是这条记录还没有加载,所以store.findRecord("product_id", product_id)将返回null。

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

1 个答案:

答案 0 :(得分:0)

您应该使用商店的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();
    });