0

我有一个 webapp,我需要从文件中获取一些数据并填写到表格中。这是带有此表的页面的代码:

public class Rules extends ContentPanel{
    private final ServerManagementAsync serverManagementSvc = GWT.create(ServerManagement.class);
    private ArrayList<PropertyItem> propslist;
    private ArrayList<PropertyItem> itemArrayList;
    private EditorGrid<PropertyItem> grid;

    public Rules(final String customerId){
        setLayout(new FlowLayout(10));

        List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

        ColumnConfig column = new ColumnConfig();
        column.setId("name");
        column.setHeader("Name");
        column.setWidth(220);

        TextField<String> text = new TextField<String>();
        text.setAllowBlank(false);
        column.setEditor(new CellEditor(text));
        configs.add(column);

        column = new ColumnConfig();
        column.setId("type");
        column.setHeader("Type");
        column.setWidth(220);

        TextField<String> typeText = new TextField<String>();
        typeText.setAllowBlank(false);
        column.setEditor(new CellEditor(typeText));
        configs.add(column);

        column = new ColumnConfig();
        column.setId("value");
        column.setHeader("Value");
        column.setWidth(220);
        configs.add(column);

        final ListStore<PropertyItem> store = new ListStore<PropertyItem>();
        propslist = getPropslist(customerId);

        for (PropertyItem propertyItem: propslist){
            store.insert(propertyItem, 0);
        }

        ColumnModel cm = new ColumnModel(configs);

        setHeading("Settings");
        setFrame(true);
        setWidth(600);
        setLayout(new FitLayout());

        grid = new EditorGrid<PropertyItem>(store, cm);
        grid.setAutoExpandColumn("name");
        grid.setBorders(true);
        add(grid);

        ToolBar toolBar = new ToolBar();
        setTopComponent(toolBar);
        setButtonAlign(Style.HorizontalAlignment.RIGHT);

        addButton(new Button("Refresh", new SelectionListener<ButtonEvent>() {
            @Override
            public void componentSelected(ButtonEvent ce) {
                store.insert(getPropslist(customerId), 5);
            }
        }));
        addButton(new Button("Add", new SelectionListener<ButtonEvent>() {

            @Override
            public void componentSelected(ButtonEvent ce) {
                store.commitChanges();
            }
        }));


    }

    public ArrayList<PropertyItem> getPropslist(String customerId){
        itemArrayList = new ArrayList<PropertyItem>();
        AsyncCallback<ArrayList<PropertyItem>> callback = new AsyncCallback<ArrayList<PropertyItem>>() {
            @Override
            public void onFailure(Throwable throwable) {

            }

            @Override
            public void onSuccess(ArrayList<PropertyItem> propertyItems) {
                itemArrayList = propertyItems;
                Window.alert("read successful");
                }
            }
        };
        serverManagementSvc.getProperties(customerId, callback);
        return itemArrayList;
    }
}

当我运行我的应用程序时,我只看到列名,单元格中没有数据(当然也没有单元格)。作为示例,我使用了这个:Ext GWT 2.2.6 Explorer(Grid)

我不明白是什么导致了这样的问题。这可能是什么原因?

4

1 回答 1

1

因为您的 propsList 是异步填充的,所以在服务器调用返回之前呈现网格。

要解决此问题,首先将商店设为像网格一样的私有财产

接下来,移动填充商店的代码:

    for (PropertyItem propertyItem: propslist){
        store.insert(propertyItem, 0);
    }

进入onSuccess回调的方法。

最后,您可能还需要调用 : grid.reconfigure(grid.getStore(), grid.getColumnModel()); 只是为了让 Grid 再次渲染。

于 2013-04-25T18:16:24.867 回答