【发布时间】:2020-03-20 13:32:55
【问题描述】:
我的表格如下:
要添加的表的 XML 视图:
<Table id="TestTable" selectionMode="Single" rows="{path: '/Collection'}" visibleRowCount="5">
<columns>
<Column width="4rem" >
<m:Text text="S.No" />
<template>
<m:Text text="{serialId}" wrapping="false" />
</template>
</Column>
<Column>
<m:Text text="Option" />
<template>
<m:Text text="{Option}" wrapping="false" />
</template>
</Column>
<Column>
<m:Text text="Quantity" />
<template>
<m:Text text="{Quantity}" wrapping="false" />
</template>
</Column>
<Column>
<m:Text text="Pin" />
<template>
<m:Text text="{Batch}" wrapping="false" />
</template>
</Column>
<Column hAlign="End" width="4rem" >
<m:Text text="Edit" />
<template>
<m:Button icon="sap-icon://edit" press="editRow" type="Reject"/>
</template>
</Column>
<Column hAlign="End" width="4rem">
<m:Text text="Drag" />
<template>
<m:Button icon="sap-icon://grid"/>
</template>
</Column>
<Column hAlign="End" width="4rem">
<m:Text text="Delete" />
<template>
<m:Button icon="sap-icon://delete" press="moveToTable1" type="Reject"/>
</template>
</Column>
</columns>
</Table>
为了将数据添加到行中,我正在使用带有表单的对话框,并且我将这些值设置为:
从对话框中获取值:
var OptionValue = sap.ui.getCore().byId("XOption").getSelectedKey(); //data from fragment
var QuantityValue = sap.ui.getCore().byId("ZQuantity").getSelectedKey();
var PinValue = sap.ui.getCore().byId("CPin").getSelectedKey();
每次在对话框中单击“确定”时,我都会尝试添加这些值(添加到行)
我在 ok 函数中尝试如下(我创建的部分函数如下):
var oTable = this.byId("TestTable");
var oData = {
WaferCollection: [
{
Option : OptionValue,
Batch: QuantityValue,
Quantity: PinValue,
}
]
};;
var testmodel = new JSONModel();
testmodel .setData(oData);
testmodel .getProperty("/collection").push(data);
testmodel .refresh(true);
this.pressDialog.close(); // close dialog
但这并没有按预期添加
我想达到的最接近的例子在下面的链接中:
但是这里的功能并没有按预期工作,当我们添加或编辑时它没有正确添加
是否有任何关于如何将数据绑定到表的指导链接,我已经看到很多关于项目而不是行的示例
感谢您对上述问题的任何帮助,并将从中学习,TIA
【问题讨论】:
-
您在 ok 函数中尝试的操作因以下几个原因不起作用: 1. 您创建了一个新模型,但您需要重用该表绑定到的模型。 2.
data未定义。 3.集合被称为三个不同的名称,“WaferCollection”、“collection”和“Collection”。
标签: sapui5