【问题标题】:Combobox failing to focus and therefore expand组合框无法聚焦并因此展开
【发布时间】:2012-04-23 20:47:15
【问题描述】:

这两天我一直在摆弄几行代码,但由于某种原因,我无法让它运行。

我想要什么:

用户从组合框中选择一个关系,随后必须从由第一个组合框过滤的人员列表中选择一个人。如果只有一个人,必须直接选择。如果它有多个,我希望组合框展开并显示检索到的人员列表。听起来很简单。

onRelationContactSelect() 是当一个人被选中时通常执行的代码。由于手动设置值时不会触发选择事件,我只是手动调用它。我在加载事件的回调中有代码,以确保从服务器检索数据。这是首先展开或选择记录所必需的。

问题:

当我有一个记录(records.length == 1)时,一切都像魅力一样。当我有超过 1 条记录时,组合框 contactCombo 无法展开。我通过 ExtJs 内部代码调试了很多,原因是没有焦点。无论我如何尝试调用contactCombo.focus(),它都会 聚焦。因此它不会扩展。为了让它更烦人,我可以使用以下代码扩展另一个组合框:

function onRelationContactSelect() {
categorieStore.load({ callback: function(r, options, success) {
    //debugger;
    //categorieCombo.focus();
    //categorieCombo.expand();
}});
categorieCombo.focus();
categorieCombo.expand();

}

可以看出,我在回调的外部调用了 focus() 和 expand(),但 categorieStore 的模式是“本地”。 categorieStore 中的数据是静态的,但仍从服务器检索。

代码:

function onRelatieSelect() {
contactStore.baseParams = {"relatieId": relatieCombo.value };
contactStore.load({callback: function(records, options, success) {
    if(records.length == 1) {
        contactCombo.setValue(records[0].get('Id'));
        onRelationContactSelect();
    } else {
        contactCombo.clearValue();
        contactCombo.focus();
        contactCombo.expand();
    }
}}); 

openTicketRelationLabel.show();
gridTicketRelatie.show();
ticketRelatieStore.load({ params: {relatieId:relatieCombo.value}});
SetRelatieInfo();
SetContractsInfo();
setSfHoursOsab();
showRelationNotifications(relatieCombo.value);
}

我已经尝试了很长时间,但似乎我根本无法从回调处理程序内部和回调处理程序外部聚焦组合框,我还没有数据。

谁能帮帮我?

【问题讨论】:

    标签: extjs combobox callback focus jsonstore


    【解决方案1】:

    在对两个不同的组合框进行沙盒处理后,我找到了解决方案。

    解决方案很奇怪但很简单:

    categorieCombo.on('select', function() {
    subcategorieCombo.focus();
    subcategorieStore.load({ callback: function(r, options, success) {
        subcategorieCombo.focus();
        subcategorieCombo.expand();
    } });
    

    在加载之前关注。

    再次关注负载的回调。

    对于这个解决方案唯一不满意的是,除了需要集中注意力两次之外,我完全不知道为什么这行得通,但它为我解决了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-31
      • 1970-01-01
      • 1970-01-01
      • 2017-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多