如何在ExtJs中的简单组合框中访问重复值

时间:2014-07-05 12:48:20

标签: java gwt extjs combobox gxt

我在GUI中有一个SimpleComboBox,它也包含一些重复的项目。假设有3个项目与“域”相同。当我选择第二个“域”或第三个“域”时,所选项目和所选索引始终指向“域”的首次出现。我如何更正,以便所选的索引/项目是正确的,而不是第一次出现项目?

具有重复值的ComboBox:

ComboBox with duplicate values

当我在第四次出现时选择“域”时,它总是指向“域”的第一次出现。

输出:

enter image description here

当我在最后一次出现时选择“192.168.1.30”时,它将指出第一次出现“192.168.1.30”。

请任何人帮助我。

private SimpleComboBox<String> domainName = new SimpleComboBox<String>();
domainName = WidgetUtil.getStringCombo("Domain Name", 12, true, domainNameList, null);
        domainName.addSelectionChangedListener(getReportSelectionListener());
        domainName.setForceSelection(true);
        domainName.setTriggerAction(TriggerAction.ALL);
 private Button New, add, remove;
 New = WidgetUtil.getButton("New", "new", "");
    New.addSelectionListener(buttonAction());
    thirdLayoutContainer.add(New);
    add = WidgetUtil.getButton("Add", "add", "");
    add.addSelectionListener(buttonAction());
    add.setStyleAttribute("paddingTop", "10px");
    thirdLayoutContainer.add(add, formData);
    remove = WidgetUtil.getButton("Remove", "remove", "");
    remove.addSelectionListener(buttonAction());

 public void componentSelected(ButtonEvent ce){
            String domain_name = null;
            if (ce.getComponent().getId().equals("remove")){
                System.err.println("Clicked remove button...");
                domain_name = domainName.getRawValue();
                domainNameList.remove(domain_name);
                systemDetailsMap.remove(domain_name);
                systemDetailsMap.remove(domain_name + "_USER_NAME");
                systemDetailsMap.remove(domain_name + "_HOST_NAME");
                systemDetailsMap.remove(domain_name + "_PASSWORD");
                domainName.removeAll();
                domainName.add(domainNameList);
                userName.clear();
                hostName.clear();
                password.clear();
                System.err.println("After remove domain name list ---> " + domainNameList);
                System.err.println("After remove map ---> " + systemDetailsMap);
            } else if (ce.getComponent().getId().equals("add")) {
                System.err.println("Clicked add button...");
                domain_name = domainName.getRawValue();
                domainNameList.add(domain_name);
                systemDetailsMap.put(domain_name, domain_name);
                systemDetailsMap.put(domain_name + "_HOST_NAME", hostName.getValue());
                systemDetailsMap.put(domain_name + "_USER_NAME", userName.getValue());
                systemDetailsMap.put(domain_name + "_PASSWORD", password.getValue());
 //                 domainName.clear();
                domainName.add(domainNameList);
 //                 domainName.reset();
                System.err.println("After add domain name list ---> " + domainNameList);
                System.err.println("After add map ---> " + systemDetailsMap);
            } else if (ce.getComponent().getId().equals("new")) {
                System.err.println("Clicked new button...");
                userName.clear();
                hostName.clear();
                password.clear();
                domainName.removeAllListeners();
                domainName.removeAll();
                domainName.clear();
                domainName.setEmptyText("Add a new domain");
                userName.setEmptyText("Add a new username");
                hostName.setEmptyText("Add a new hostname");
                password.setEmptyText("Add a new password");
                domainName.addSelectionChangedListener(getReportSelectionListener());
            }
        }
        };


 private SelectionChangedListener<SimpleComboValue<String>> getReportSelectionListener(){
    SelectionChangedListener<SimpleComboValue<String>> ReportListener = new SelectionChangedListener<SimpleComboValue<String>>() {
        @Override
        public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
            SimpleComboValue<String> selectedValue = se.getSelectedItem();
            String value = selectedValue.getValue();
            System.err.println("Selected Value ---> " + selectedValue.getValue());
            if (value != null && !value.equals("---New---") ){
                userName.clear();
                hostName.clear();
                password.clear();
                userName.setValue(systemDetailsMap.get(value + "_USER_NAME").toString());
                hostName.setValue(systemDetailsMap.get(value + "_HOST_NAME").toString());
                password.setValue(systemDetailsMap.get(value + "_PASSWORD").toString());
            } 
        }
    };
    return ReportListener;
}

请帮帮我。提前谢谢。

1 个答案:

答案 0 :(得分:0)

我没有使用Ext-gwt只是标准的ext-js,但我想我知道你需要什么!您应该定义显示和值字段。

Ext.create('Ext.form.ComboBox', {
    store: xyz,
    queryMode: 'local',
    displayField: 'name',
    valueField: 'id',
    renderTo: Ext.getBody()
});

您必须确保重复的项目获得唯一ID。我认为如果在ext-js中这是可能的,那么在ext-gwt中也应该是可能的!