2015-11-06 33 views
0

我创建了几个treetables,每个treetables都放在它自己的div上。 主要可再现的问题,我已经有了:SapUi5 TreeTable在jQuery.getJSON()调用中不同呈现

  • 直接创建表 - >一切正常(见图片1)
  • 创建asynchron jQuery的通话中的表:第一个添加的表得到总是垂直滚动条(见图像2)

这里是代码:

var oData = { root: ...} 

// code for image 2 
jQuery.getJSON(url, function (result) { 
    createTable(oData['table1'], 'table1') 
    createTable(oData['table2'], 'table2') 
}) 

// code for image 1 
createTable(oData['table1'], 'table1') 
createTable(oData['table2'], 'table2') 

function createTable(oData, codeSample){ 
    var oTable = new sap.ui.table.TreeTable({ 
    columns: [ 
     new sap.ui.table.Column({label: "trans_class", template: "trans_class"}) 
     , new sap.ui.table.Column({label: "Checked", template: "checked"}) 
    ], 
     height: '100%', 
     selectionMode: sap.ui.table.SelectionMode.None, 
     enableColumnReordering: false, 
     expandFirstLevel: false, 
     visibleRowCount : INITIAL_ROW_COUNT_IN_TABLE, 
     visibleRowCountMode : sap.ui.table.VisibleRowCountMode.Auto, 
     toggleOpenState: function(oEvent) { 
     var isLeafExpanded = oEvent.getParameter("expanded"); 
     if(isLeafExpanded){ 
      oTable.setVisibleRowCount(oTable.getVisibleRowCount() + 2) 
      SUM_INDEX_TOGGLE = SUM_INDEX_TOGGLE + 2 
     }else{ 
      oTable.setVisibleRowCount(oTable.getVisibleRowCount() - 2) 
      SUM_INDEX_TOGGLE = SUM_INDEX_TOGGLE - 2 
     } 
     } 
    }) 

    var oModel = new sap.ui.model.json.JSONModel(); 
    oModel.setData(oData); 
    oTable.setModel(oModel); 
    sap.ui.getCore().setModel(oModel, codeSample); 
    oTable.bindRows("/root"); 
    oTable.expand(4); // expand Sum Row 

    //Bring the table onto the UI 
    oTable.placeAt(codeSample); 

}

我该如何解决这个问题。我希望我所有的桌子看起来都一样。 image 1

image 2

回答

0

解决方法:添加一个简单的文本框,添加后隐藏的treetable中:

addSimpleHiddenTextField(HIDDEN_TEXTFIELD) 
for(var i in config.TABLES){ 
    createTableAndPlaceIt(result[i], i, config.TABLES[i]) 
} 
hideSimpleTextField(HIDDEN_TEXTFIELD)