代码之家  ›  专栏  ›  技术社区  ›  DeKoss

EXT js如何同步调用Store

  •  0
  • DeKoss  · 技术社区  · 9 年前

    我需要弄清楚如何同步调用这个函数。

        fetchData: function(recs){
        store = Ext.getStore('OutOfBalanceList');
        store.reload({
            params: {
                startDate: searchForm.startDate,
                endDate: searchForm.endDate,
                cusip: searchForm.cusip,
                account: searchForm.account
            },
            callback: function (records, options, success) {
                recs = records.length;
                return recs;
            }
        });
    },  
    

    我感谢所有关于异步的讲道,但在这种情况下,我必须使用同步调用,因为当返回的数据为空时,我必须用不同的参数再次调用。目前,这最终是一个无限循环,因为“recs”在外部没有更改!

    非常感谢

    1 回复  |  直到 9 年前
        1
  •  1
  •   Robert Watkins    9 年前

    不要试图使其同步。在回调方法中执行“使用不同参数再次调用”。大致如下:

    fetchData: function(recs) {
      var me = this;
      store = Ext.getStore('OutOfBalanceList');
      store.reload({
        params: {
          startDate: searchForm.startDate,
          endDate: searchForm.endDate,
          cusip: searchForm.cusip,
          account: searchForm.account
        },
        callback: function (records, options, success) {
          if (records.length == 0) {
            me.fetchDataWithDifferentParameters();
          }
        }
      });
    }
    

    如果您要使用JavaScript框架并调用外部数据源,那么学习如何使用回调非常重要。