GWT - Add and remove nodes in celltree

前端 未结 3 932
梦谈多话
梦谈多话 2021-01-05 05:16

Here I have an complete and very easy example to dynamically add/remove nodes to an celltree. My example is not working very well. It seems there is an refresh problem. Only

3条回答
  •  无人及你
    2021-01-05 05:45

    This is somehow a known problem with CellTree.
    The reason for the refresh problem is that in the getNodeInfo() function you create a new ListDataProvider instance for each CellTree level.
    The CellTree only updates/refreshes itself if you update the items in that ListDataProvider. I believe that your removeMenu() and addSubMenu() functions add and remove items from the original list stored in your MyNode class but won't update the list in the corresponding ListDataProviders (you can try to check that in debug mode).
    The reason why the CellTree is refreshed when you close and re -open the nodes is because when you re-open the nodes the getNodeInfo() is called again and the whole CellTree structure will be constructed again (including the new menu or without the removed one respectively).

    There are two possible solutions:

    1. Keep a reference for each of the ListDataProviders somewhere and call remove/add on that list (although you do that I assume that the items are not really added/removed there).
    2. Programatically close all nodes and re-open it.

    Both are somehow a PITA to implement. Unfortunately there is no easy way around it.

提交回复
热议问题