Combobox Extjs组合框-doQuery回调?

Combobox Extjs组合框-doQuery回调?,combobox,extjs,Combobox,Extjs,我正在使用以下组合框: var cb = new Ext.form.ComboBox({ store: someDs, fieldLabel: 'test', valueField:'name', displayField:'name_id', typeAhead: true, minChars: 3,

我正在使用以下组合框:

            var cb = new Ext.form.ComboBox({
            store: someDs,              
            fieldLabel: 'test',
            valueField:'name',
            displayField:'name_id',
            typeAhead: true,
            minChars: 3,
            triggerAction: 'query'
        });
因此,当用户输入3个字符时,将向服务器发出一个查询,显示正确的结果

现在,我尝试使用combobox的doQuery()函数以编程方式进行用户输入。调用doQuery()方法后,我想通过setValue()选择一个项

问题是setValue()无法选择propper值,因为在调用它时,通过doQuery()启动的请求尚未完成。 所以我需要一个回调函数,在其中我可以使用setValue()-但是doQuery()似乎没有回调函数


有什么想法吗?谢谢

我自己回答,因为评论中没有代码格式

伊戈尔:它是有效的,但感觉像是一个丑陋的黑客,然后是一个干净的解决方案。 为了更好地理解,我解释了情况: 我有一个网格面板。当用户单击此面板上的一行时,我想在组合框中预选所选的值。因为有很多数据,我想使用combobox的doQuery函数来降低它。 在GridPanel的rowClick事件中,我有以下代码:

var myrec = Ext.getCmp('mygrid').store.getAt(rowIndex);

mycombo.store.on('load', myfn1 = function() {
    // When the store has finisihed loading, select item in the combobox
    mycombo.setValue(myrec.data.customer_id);
    // Remove the function assigend to the load event... 
    // ...(when user types directly to the combobox instead clicking on a row...)
    mycombo.store.un('load', myfn1);
});
// setValue has to be called again, because the load-event doesn't fires
// when doQuery is called with same params
mycombo.setValue(myrec.data.customer_id);
// Call do query to fill the combo only with the relevant values
mycombo.doQuery(myrec.data.customer_id);

ComboBox
有一个
beforequery
事件,您可以选择拦截查询,自己加载存储,然后取消
ComboBox
查询。此外,在您的示例中,您正在将处理程序函数保存到一个变量,然后从处理程序中调用
un
。这完全没有必要,因为您可以将选项
{single:true}
作为第四个参数传递给
on
(第三个参数是
范围

如果我理解您的问题,您希望将组合的值设置为某个值,例如customer id
123
。问题是没有加载customer
123
的记录,因此存储中没有关于该客户的任何数据。我说得对吗

然后,你想做的是(这不一定适合你的情况,只是一个让你开始的方向):


嗯,也许可以选择使用分配给组合框的存储的“load”事件:someDs.store.on('load',function(){cb.setValue('myval');});cb.doQuery(“myval”);但我不确定这是否是一个优雅的解决方案……这是我考虑的选项之一。它能按你想要的方式工作吗?
var myrec = Ext.getCmp('mygrid').store.getAt(rowIndex);

mycombo.store.on('load', myfn1 = function() {
    // When the store has finisihed loading, select item in the combobox
    mycombo.setValue(myrec.data.customer_id);
    // Remove the function assigend to the load event... 
    // ...(when user types directly to the combobox instead clicking on a row...)
    mycombo.store.un('load', myfn1);
});
// setValue has to be called again, because the load-event doesn't fires
// when doQuery is called with same params
mycombo.setValue(myrec.data.customer_id);
// Call do query to fill the combo only with the relevant values
mycombo.doQuery(myrec.data.customer_id);
combo.on('beforequery', function(q) {
  q.cancel = true;
  var id = q.query;
  combo.setDisabled(true);
  combo.store.on('load', function() {
    combo.setValue(id);
  }, combo.store, {single: true});
  combo.store.reload({
    customer_id: id
  });

  return q;
});