Checkbox 使用GAS在树中传播状态复选框
我在stackPanel中的scrollPanel中有一棵树该树包含300多个treeitems,每个treeitems都有一个复选框。 根据userproperty的状态,我希望将单击的复选框的状态传播到其子树。 我有一个方法来查找每个(子)树项的每个复选框的ID。该方法也被用于构建树 每个复选框都有(相同的)onValueChangeHandlerCheckbox 使用GAS在树中传播状态复选框,checkbox,google-apps-script,treeview,Checkbox,Google Apps Script,Treeview,我在stackPanel中的scrollPanel中有一棵树该树包含300多个treeitems,每个treeitems都有一个复选框。 根据userproperty的状态,我希望将单击的复选框的状态传播到其子树。 我有一个方法来查找每个(子)树项的每个复选框的ID。该方法也被用于构建树 每个复选框都有(相同的)onValueChangeHandler function onChangeStatusChkTreeItem(e) { // Set all checkboxes of subtree
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()的末尾