1

我使用 smartgwt 2.5。我有一个数据绑定的treegrid,它从数据库中获取一个json并构建树。这很好用。问题是当我尝试重新做父母时

一开始,树看起来像:

在此处输入图像描述

我从数据库中获取的 json:

[{"id":"a","ReportsTo":"root","isFolder":"true","isOpen":"false"},{"id":"b","ReportsTo":"c","isFolder":"false", "isOpen":"false"},{"id":"c","ReportsTo":"root","isFolder":"true","isOpen":"true"},{"id":"d","ReportsTo":"a","isFolder":"false","isOpen":"false"}]

在reparent b之后(将b拖到文件夹c并将其放入c)所有叶子都得到文件夹:

http://i.stack.imgur.com/lLHdX.png

这是发送到服务器:

{
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)     "dataSource":"isc_RestDataSource_0", 
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)     "operationType":"update", 
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)     "data":{
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)         "id":"b", 
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)         "ReportsTo":"c", 
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)         "isFolder":false, 
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)         "isOpen":"false"
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)     }, 
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)     "oldValues":{
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)         "id":"b", 
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)         "ReportsTo":"a", 
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)         "isFolder":false, 
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)         "isOpen":"false"
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4)     }
12:46:52,773 INFO  [stdout] (http--127.0.0.1-7443-4) }

站点刷新后,树正确显示:

a
c
-b
-d

我的树形网格代码:

公共类 FavoritesGrid 扩展 TreeGrid {

public FavoritesGrid() {
    setWidth("12%");
    setShowConnectors(false);
    setShowResizeBar(true);
    setCanReorderRecords(true);
    setCanAcceptDroppedRecords(true);
    setCanDragRecordsOut(true);
    setCanReparentNodes(true);
    setDragDataAction(DragDataAction.MOVE);
    setAutoSaveEdits(false);
    setAutoFetchData(false);
    setLoadDataOnDemand(false); //load everything

    setHeight("50%");

    RestDataSource ds = new RestDataSource();
    ds.setRecordXPath("/");
    ds.setDataFormat(DSDataFormat.JSON);

    OperationBinding fetch = new OperationBinding();
    fetch.setOperationType(DSOperationType.FETCH);
    fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
    fetch.setDataFormat(DSDataFormat.JSON);

    OperationBinding add = new OperationBinding();
    add.setOperationType(DSOperationType.ADD);
    add.setDataProtocol(DSProtocol.POSTMESSAGE);
    add.setDataFormat(DSDataFormat.JSON);

    OperationBinding update = new OperationBinding();
    update.setOperationType(DSOperationType.UPDATE);
    update.setDataProtocol(DSProtocol.POSTMESSAGE);
    update.setDataFormat(DSDataFormat.JSON);

    ds.setOperationBindings(fetch, update, add);

    ds.setDataURL("/Kronos/Favorites");

    DataSourceTextField key = new DataSourceTextField("id", "id");
    key.setPrimaryKey(true);
    key.setRequired(true);
    DataSourceTextField parent = new DataSourceTextField("ReportsTo",
            "ReportsTo");
    parent.setRequired(true);
    parent.setForeignKey("id");
    parent.setRootValue("root");

    ds.setFields(key, parent);

            //define properties
    Tree tree = new Tree();
    tree.setDefaultIsFolder(false); //default the nodes should be leafs
    tree.setRootValue("root");  
    tree.setNameProperty("id");  
    tree.setIdField("id");  
    tree.setParentIdField("ReportsTo");  
    //the setOpenProperty also doesn't work
    //if i set it smartgwt displays all folder opened
    tree.setOpenProperty("isOpen"); 
    //setIsFolderProperty is being ignored after reparent, need to refresh the site for correction
    tree.setIsFolderProperty("isFolder"); 

    setDataProperties(tree);

    setDataSource(ds);

    fetchData();
}
}

有人可以帮我吗?

4

0 回答 0