0

概述:

我使用动态 GXT ListField 列出数据库中某个位置的所有批准者并预先选择选定的批准者(isSelected==true)。

问题:

看起来商店有正确的数据并在列表中选择了正确的序数,但可见 ListField 中的数据仍然显示第一次加载 ListField 时的数据。我无法刷新列表 UI 以显示来自第二个位置的项目。

例子:

位置1:

所有批准人={a,b,c,d,e,f,g,h,i,j}

选定的批准者 = {a,b,c}

display={ [a],[b],[c] ,d,e,f,g,h,i,j} 其中[] = 选中

位置2:

所有批准人={x,y,z,l,m,n,o,p,q,r}

选定的批准者 = {x,y,z,l}

display={ [a],[b],[c],[d] ,e,f,g,h,i,j} 其中 [] = 选中(错误!)

预期 = { [x],[y],[z],[l] ,m,n,o,p,q,r}

注意:它现在选择了4,这意味着它使用了正确的商店,尽管显示仍然显示 location1 数据:(

代码:

ListField<Approver>() approversListField ;

    OnModuleload() //..not including for simplicity
    {
    :

    panel.add(getInitialApproverList());
    loadApprovers(1);
    loadApprovers(2);
    }

        private Widget getInitialApproverList() {

            approversListField = new ListField<Approver>();
            approversListField.setEmptyText("employee last name");
            approversListField.setTemplate(getApproverTemplate());
            approversListField.setFieldLabel("Approvers *");
            approversListField.setId("approvers");
            approversListField.setEmptyText("No approvers available.");

                return approversListField;

        }

        private void loadApprovers(int locationID) {

                ListStore<Approver> approversStore = dataStores.getApprovers(locationID);           
                approversListField.setStore(approversStore);
                approversListField.setValueField("userID");
                approversStore.addStoreListener(new StoreListener<Approver>() {
                    @Override
                    public void storeDataChanged(StoreEvent<Approver> se) {
                        super.storeDataChanged(se);

                        approversListField.fireEvent(Events.Render);

                    }
                });

                /**
                 * // * Attach render listener, had to do it on render because select()
                 * // * method only works onrender // *
                 * http://www.sencha.com/forum/showthread.php?55659-Selecting-Items-in-ListField-After-Load // *
                 */
                approversListField.addListener(Events.Render, new Listener<BaseEvent>() {
                    @Override
                    public void handleEvent(BaseEvent be) {

                        ListViewSelectionModel<Approver> approverListFieldSelectionModel = approversListField.getListView()
                                .getSelectionModel();


                        approversListField.getListView().refresh();
                        approverListFieldSelectionModel.deselectAll();                                      

                        System.out.println("approversStore size:"+approversListField.getStore().getCount());
                        for (int i = 0; i < approversListField.getStore().getCount(); i++) {
                            Approver app = approversListField.getStore().getAt(i);

                            System.out.println(app);                    
                            if (app.isSelected() == true) {

                                System.out.println("FOUND THE APPROVER!  " + i);
                                approverListFieldSelectionModel.select(app, true);                                                                              

                            }
                        }

                    }
                });

        }
4

1 回答 1

0

终于自己找到了。把它留在这里是为了它的价值。

看起来如果商店发生变化,您也必须为 Listfield 的 View 商店重置商店。

approversListField.getListView().setStore(approversListField.getStore());

无需触发渲染。可以在存储数据更改时完成所有操作。

approversStore.addStoreListener(new StoreListener<Approver>() {
            @Override
            public void storeDataChanged(StoreEvent<Approver> se) {
                super.storeDataChanged(se);

                ListViewSelectionModel<Approver> approverListFieldSelectionModel = approversListField.getListView()
                        .getSelectionModel();
                approverListFieldSelectionModel.deselectAll();
                approversListField.getListView().setStore(approversListField.getStore());
                approversListField.getListView().refresh();
                for (int i = 0; i < approversListField.getStore().getCount(); i++) {                    
                    Approver app = approversListField.getStore().getAt(i);
                    if (app.getIsselected() == true) {                  
                        approverListFieldSelectionModel.select(i, true);

                    }
                }

            }
        });
于 2013-08-14T18:12:54.627 回答