[英]SAPUI5 TreeTable select children when parent is selected
我有一個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.選擇父對象后,獲取父對象的綁定路徑並循環所有子對象的綁定路徑,並更新相應的屬性,該屬性使用模型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
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.