2017-09-14 83 views
0

我有一個用於過濾類別的SAPUI5 TreeTable。我想要的是,當選擇父類別時,應該選擇所有的孩子,當父母被取消選擇時,它的孩子應該被取消選擇,不管它們是否被摺疊。問題是我不能使用索引,因爲顯然它們基於摺疊項目而不同。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

您可以通過

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 
     } 
    } 
}