P. *_*sow 5 javascript treetable sapui5
问题是:
当我在运行时添加行时,我试图使 TreeTable 中的节点保持展开状态。TreeTable 的默认行为是,当它发生某些情况时,它会再次呈现并且所有节点都会折叠。
API 只提供了保持第一级扩展的方法,但我也喜欢保持较低级别的节点扩展。我怎样才能做到这一点?
添加行之前:

添加一行后:

期待:

[编辑]
我已经尝试通过使用 Expand(iRowIndex) 来获得正确的行为,但就我而言,TreeTable 的生命周期(添加内容、重新渲染)没有帮助。
我在做什么:
我正在尝试使用拖放功能添加数据。当我们尝试将内容添加到 TreeTable 的特定位置时,我们必须获得父元素和子元素的正确位置。不幸的是,在添加上述内容后,第二个+级别被隐藏,这会扰乱我的拖放操作,因为表格行在折叠时具有不同的 ID。
基本上我需要一个像 ."setExpandFirstLevel(true)" 这样的 TreeTable 函数来处理所有其他级别。
它有点脏,但是您可以通过在迭代每个行项目时调用它来使用TreeTables方法expand(iRowIndex)
编辑:我创建了一个工作示例(见下文),表明您不需要使用 rowID 或向 DOM 添加任何控件。拖/放操作唯一要做的就是仅使用模型将子节点添加到所选节点。
但实际上,expand(rowIndex)工作得很好,所有可见行都会立即展开(但请参见下面的 NB2)
NB1:为了简单起见,我没有创建完整的拖/放示例,但单击“添加子节点”按钮应该模仿“放置”事件。
NB2:显然该方法有一个错误expand:它只扩展可见的树项。滚动后的任何项目都不会展开...
sap.ui.controller("view1.initial", {
onInit : function(oEvent) {
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData({
data : [
{
name : "node1",
description : "Lorem ipsum dolor sit amet",
data : [
{
name : "node1.1",
description : "Cras pretium nisl ac ex congue posuere"
},
{
name : "node1.2",
description : "Consectetur adipiscing elit",
data: [
{
name : "node1.2.1",
description : "Maecenas accumsan ipsum diam"
}
]
},
{
name : "node1.3",
description : "Sed tristique diam non imperdiet commodo"
},
{
name : "node1.4",
description : "Consectetur adipiscing elit",
data: [
{
name : "node1.4.1",
description : "Maecenas accumsan ipsum diam",
data: [
{
name : "node1.4.1.1",
description : "Maecenas accumsan ipsum diam",
data: [
{
name : "node1.4.1.1.1",
description : "Maecenas accumsan ipsum diam",
data: [
{
name : "node1.4.1.1.1.1",
description : "Maecenas accumsan ipsum diam"
}
]
}
]
}
]
}
]
},
{
name : "node1.5",
description : "Sed tristique diam non imperdiet commodo"
},
{
name : "node1.6",
description : "Consectetur adipiscing elit",
data: [
{
name : "node1.6.1",
description : "Maecenas accumsan ipsum diam"
}
]
},
{
name : "node1.7",
description : "Sed tristique diam non imperdiet commodo"
},
]
},
]
});
this.getView().setModel(oModel);
},
onAfterRendering : function() {
this._doExpandAll();
},
addNode : function(oEvent) {
var oContext = oEvent.getSource().getBindingContext();
var obj = oContext.getObject();
var oNew = { name : "New node", description : "New description"};
if (!obj.data) obj.data = []; //if no child array, create empty one
obj.data.push(oNew);
this.getView().getModel().setProperty(oContext.getPath(), obj);
this._doExpandAll();
},
_doExpandAll : function() {
var oTTbl = this.getView().byId("tbl");
for (var i=0; i<oTTbl.getRows().length; i++) {
oTTbl.expand(i);
}
}
});
var app = new sap.m.App({});
var oView = sap.ui.xmlview({
viewContent: jQuery("#view1").html()
});
app.addPage(oView);
app.placeAt("uiArea");Run Code Online (Sandbox Code Playgroud)
<script id="sap-ui-bootstrap"
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-libs="sap.m"></script>
<script id="view1" type="ui5/xmlview">
<mvc:View
controllerName="view1.initial"
xmlns:t="sap.ui.table"
xmlns="sap.ui.commons"
xmlns:mvc="sap.ui.core.mvc" >
<t:TreeTable id="tbl" rows="{path:'/',parameters:{arrayNames:['data']}}" visibleRowCount="10">
<t:columns>
<t:Column>
<t:label><Label text="name" /></t:label>
<t:template><TextView text="{name}" /></t:template>
</t:Column>
<t:Column>
<t:label><Label text="description" /></t:label>
<t:template><TextView text="{description}" /></t:template>
</t:Column>
<t:Column>
<t:label><Label text="" /></t:label>
<t:template><Button text="Add child node" press="addNode"/></t:template>
</t:Column>
</t:columns>
</t:TreeTable>
</mvc:View>
</script>
<div id="uiArea"></div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7853 次 |
| 最近记录: |