gpt4 book ai didi

javascript - SAPUI5 TreeTable 在选择父项时选择子项

转载 作者:行者123 更新时间:2023-11-30 15:02:58 24 4
gpt4 key购买 nike

我有一个 SAPUI5 TreeTable 用于过滤类别。我想要的是,当选择父类别时,应选择所有子类别,而当取消选择父类别时,应取消选择其子类别,无论它们是否折叠。问题是我不能使用索引,因为显然它们因折叠的项目而异。

            <t:TreeTable
id="treeCategoriesFilterItem"
rows="{path:'tree_categories>/', parameters: {arrayNames:['categories']}}"
selectionMode="MultiTogle"
enableSelectAll="false"
ariaLabelledBy="title"
visibleRowCountMode="Fixed"
rowSelectionChange="onCategoriesRowSelectionChange"
>
<t:columns>
<t:Column width="100%">
<Label text="{i18n>label.ticket.category}"/>
<t:template>
<Text text="{tree_categories>name}"/>
</t:template>
</t:Column>
</t:columns>
</t:TreeTable>

最佳答案

你可以通过

1.收到树表数据后,oEvent.getSource().oKeys 将具有父子信息,将其保存在表自定义数据中。此数据有助于获取所选父项的子项。

var oRowsBinding = oTable.getBinding("rows");
oRowsBinding.attachDataReceived(function(oEvent){
var oKeys = oEvent.getSource().oKeys;//will have the parent and child information.
oTable.data("keys", oKeys);//store the key values
}.bind(this));

2。选择父项时,获取父项的绑定(bind)路径并循环所有子项的绑定(bind)路径,并使用模型 setProperty() 更新选择子项的相应属性。取消选择也是如此。

onSelection: function(oEvent){
var oSource = oEvent.getSource();
bPCBEnabled = oSource.getSelected(),
oRow = oSource.getParent(),
oTable = oRow.getParent(),
iHierarchyLevel = oRow.getBindingContext("oModel").getObject().HierarchyLevel;
if(iHierarchyLevel === 1 && oTable && oTable.data() && oRow){
if(bPCBEnabled)//expand/collapse parent
oTable.expand(oRow.getIndex());
else
oTable.collapse(oRow.getIndex());

var oKeys = oTable.data().keys,
sPath = oRow.getBindingContext("oModel").sPath,//parent binding path
oChilds = oKeys[sPath.replace("/", "")];
for(var iKey in oChilds){
sChildPath = "/" +oChilds[iKey],//child binding path
oModel = oTable.getModel("oModel"),
oModel.setProperty(sChildPath + "/Enabled", bPCBEnabled);//change to your corresponding model property which tells is selected/deselected
}
}
}

关于javascript - SAPUI5 TreeTable 在选择父项时选择子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46219685/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com