如何在ExtJS6中为远程组合框赋值并获得相应的记录?

如何在ExtJS6中为远程组合框赋值并获得相应的记录?,extjs,extjs6,Extjs,Extjs6,假设我有一对由简单远程存储支持的组合框。当任一组合框选择使用所选记录(而不是值)更改时,我需要执行一些任务 现在我试图在只有id值的情况下触发doTask(),结果如下: initData: function(id1, id2){ this.lookupReference('combo1').setValue(id1); this.lookupReference('combo2').setValue(id2); var self = this; var wait

假设我有一对由简单远程存储支持的组合框。当任一组合框选择使用所选记录(而不是值)更改时,我需要执行一些任务

现在我试图在只有
id
值的情况下触发
doTask()
,结果如下:

initData: function(id1, id2){
    this.lookupReference('combo1').setValue(id1);
    this.lookupReference('combo2').setValue(id2);

    var self = this;
    var waitTimer = Ext.Function.interval(function(){

        var record1 = this.lookupReference('combo1').getSelection();
        var record2 = this.lookupReference('combo2').getSelection();

        if(record1 && record2){
            window.clearInterval(waitTimer);

            this.doTask(record1, record2);
        }
    }, 100, self);
}

有更好的方法吗?

您应该看看您的方法是否适用于通过键入输入的值。我不确定


您还可以使用
findRecordByValue
wiht
getValue
。这将使用通过选择或键入选择的值搜索存储。另一方面,如果键入的值不在存储区中,则该值可能为空。

为什么在这里使用计时器?是因为要等待记录加载这些ID吗?是的,如果立即调用getSelection()则为null。基本上,问题是如何捕获当前值的记录何时加载,以便我可以访问它。
initData: function(id1, id2){
    this.lookupReference('combo1').setValue(id1);
    this.lookupReference('combo2').setValue(id2);

    var self = this;
    var waitTimer = Ext.Function.interval(function(){

        var record1 = this.lookupReference('combo1').getSelection();
        var record2 = this.lookupReference('combo2').getSelection();

        if(record1 && record2){
            window.clearInterval(waitTimer);

            this.doTask(record1, record2);
        }
    }, 100, self);
}