我已经实现了一个 TreeGrid,它绑定到 SmartGWT 中的 RestDataSource。为了提供计数,我有一个名为 的 TreeGridField requirementListing
,它是在客户端计算的。每次更新后,我都会运行一个(重新)计算数值的函数。
编号看起来像这样。
1. Item 1 in level 0
|_ 1.1 item 1 in level 1
|_ 1.1.1 item 1 in level 2
2. Item 2 in level 0
为了在更新节点后触发计算功能,我使用了几个处理程序,如
DataArrivedHandler
EditCompleteHandler
RemoveRecordClickHandler
所有这些都正常工作,唯一不更新编号的情况是,如果我将项目移动到另一个文件夹(或文件夹内)。我试图从DropCompleteHandler
and调用计数函数FolderDropHandler
,它们似乎都不起作用。阅读树后 - 拖放节点 - 刷新?我正在使用DeferredComand
,它在 Chrome 中有效,但在 Firefox 中无效。使用最新版本的 SmartGWT,它也无法在 Chrome 中运行。
requirementTreeGrid.addDropCompleteHandler(new DropCompleteHandler() {
@SuppressWarnings("deprecation")
@Override
public void onDropComplete(DropCompleteEvent event) {
SC.logInfo("Drop complete");
DeferredCommand.addCommand(new Command() {
public void execute() {
treeNumerator.addTreeNumeration(requirementTreeGrid);
requirementTreeGrid.refreshFields();
requirementTreeGrid.redraw();
SC.logInfo("tree updated");
}
});
}
});
requirementTreeGrid.addFolderDropHandler(new FolderDropHandler() {
//same code like above
});
}
});
由于 DeferredCommand 已被弃用,我也尝试过,Scheduler.scheduleDeferred()
但遗憾的是这也没有成功。
我的计数函数:
public void addTreeNumeration(TreeGrid treeGrid) {
this.levels = new Integer[numberOfLevels];
for (int i=0; i<=numberOfLevels-1;i++){ //fill array with 1
levels[i] = 1;
}
TreeNode rootNode = treeGrid.getTree().getRoot(); // root element of tree
int levelIndex = 0;
calculateRequirementTreeNumeration(treeGrid, treeGrid.getTree()
.getChildren(rootNode), levelIndex, levels);
}
private void calculateRequirementTreeNumeration(TreeGrid treeGrid,
TreeNode[] lvlNodes, int levelIndex, Integer[] levels) {
levels[levelIndex]=1;
for (TreeNode lvlNode : lvlNodes) {
String numerationLabel = "";
for (int i = 0; i <= levelIndex; i++) {
numerationLabel = numerationLabel + levels[i] + ".";
}
SC.logInfo("->Req " + numerationLabel);
lvlNode.setAttribute("requirementListing", numerationLabel);
// weitere ebene?
if (treeGrid.getTree().hasChildren(lvlNode)) {
SC.logInfo(numerationLabel + " -> new level");
if (levelIndex + 1 < numberOfLevels) { // nur "numberOfLevels" ebenen werden berechnet.
calculateRequirementTreeNumeration(treeGrid, treeGrid
.getTree().getChildren(lvlNode), levelIndex + 1,
levels);
} else {
deleteRequirementTreeNumeration(treeGrid, treeGrid
.getTree().getChildren(lvlNode), levelIndex + 1);
}
}
levels[levelIndex]++;
}
}
我还调试了客户端开发人员控制台的问题,在我看来,问题是在删除之后但在 RestDataSource 发送响应之前完成了计算。看起来我刚刚移动的节点已经消失了,直到 DS 发送响应。(因此 requirementsListing 字段没有更新)
JavaScript调试:
12:35:35.724:MUP5:INFO:Log:Drop complete
12:35:35.736:INFO:Log:->Req 1.
12:35:35.736:INFO:Log:1. -> new level
12:35:35.736:INFO:Log:->Req 1.1.
12:35:35.736:INFO:Log:->Req 1.2.
12:35:35.736:INFO:Log:->Req 2.
12:35:35.736:INFO:Log:2. -> new level
12:35:35.737:INFO:Log:->Req 2.1.
12:35:35.737:INFO:Log:->Req 2.2.
12:35:35.737:INFO:Log:->Req 2.3.
12:35:35.737:INFO:Log:->Req 3.
12:35:35.738:INFO:Log:3. -> new level
12:35:35.738:INFO:Log:->Req 3.1.
12:35:35.742:INFO:Log:->Req 3.2.
12:35:35.744:INFO:Log:->Req 3.3.
12:35:35.744:INFO:Log:3.3. new level
12:35:35.744:INFO:Log:->Req 3.3.1.
12:35:35.745:INFO:Log:->Req 3.3.2.
........
12:35:35.756:DEBUG:TreeGrid:isc_TreeGrid_0:delaying adjustOverflow: childClear
12:35:35.866:INFO:Log:tree updated
12:35:35.878:XRP8:INFO:ResultTree:isc_ResultTree_0 (created by: isc_TreeGrid_0):Updating cache: operationType 'update', 1 rows update data:
[
{id: 32,
parentId: 40,
requirement: "g",
typ: undef,
cluster: undef}
]
12:35:35.878:XRP8:DEBUG:ResultTree:isc_ResultTree_0 (created by: isc_TreeGrid_0):updated cache: 0 row(s) added, 1 row(s) updated, 0 row(s) removed.
也许有人遇到过类似的问题?我真的不知道如何解决这个问题。
我的 SmartGWT 版本:4.1d /SmartClient v9.1d_2013-08-11/LGPL(建于 2013-08-11)