使用GAS在树中传播状态复选框



我在stackPanel中的scrollPanel中有一个树,该树包含超过300个树项,每个树项都有一个复选框。根据用户属性的状态,我希望将被单击的复选框的状态传播到它的子树项。我有一个方法来查找每个(子)树项的每个复选框的id。该方法也已用于构建树。

每个复选框有(相同的)onValueChangeHandler

function onChangeStatusChkTreeItem(e)
{ // Set all checkboxes of subtreeitems TRUE or FALSE in case 'propagate' will be true
     var app = UiApp.createApplication();
     var chkSource = e.parameter.source;
     var triSource = chkSource.replace(chkPrefix, triPrefix); // chkPrefix and triPrefix are global variables
     var status = (e.parameter.button == 1); // New status of the checkbox
     var propagate = userProperties.getProperty('propagateToSubFofolders');
     propagate = ((propagate == true) || (propagate == 'true'));
     if (propagate == false)
     { // Just this checkbox
        userProperties.setProperty(triSource, status);
        app.getElementById(chkSource).setValue(status, true); // (`false` makes no difference) 
     }
     else
     { // Include subtree as well
        var props = userProperties.getProperties();
        var propsChanged = {};
        var changes = 0; 
        updateSubTree_(triSource, chkSource);
        if (changes > 0) userProperties.setProperties(propsChanged);
     }
     function updateTree_(treeItemId, chkTreeItemId)
     { // Internal function : Set all subtreeitems as well
        if (props[treeItemId] !=  status)
        { // Update needed
           changes++;
           propsChanged[treeItemId] = status;
           var chk = app.getElementById(chkTreeItemId);
           chk.setValue(status, false);  .. chk.setValue(status, true) maakt geen verschil
           // loop through the children of treeItemId (pseudo code --> tested)
           for each child
           {
              newTriId --> created
              newChkId --> created based on newTriId
              updateTree_(newTriId, newChkId);
           }
        }
     }
}

但是树中的复选框不会被更新。

所以我的问题是:我错过了什么?

除非我错过了一些我很确定使用UiApp创建的应用程序是不知道自己的状态,直到你调用return app;

你的代码所做的任何更改将不会反映,直到发生这种情况,包括在你的onValueChangeHandler()的末尾

最新更新