选择父级时,SAPUI5 TreeTable选择子级

时间:2017-09-14 12:50:33

标签: javascript sapui5

我有一个用于过滤类别的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 个答案:

答案 0 :(得分:2)

你可以通过

实现它

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 
        }
    }
}
相关问题