abap 添加按钮,在SAPUI5表中添加新行的按钮

I am trying to add new lines on a SAPUI5 table by a click of a button. I have seen plenty of online tutorials but I have not found exactly my use case.

The JSON is loaded through a mock server for now (for testing purposes and has this structure:

{

"Invoices": [

{

"ProductName": "Pineapple",

"Quantity": 21,

"ExtendedPrice": 87.2000,

"ShipperName": "Fun Inc.",

"ShippedDate": "2015-04-01T00:00:00",

"Status": "A"

},

...

]

}

I have a table that is defined like this in the view:

xmlns:html="http://www.w3.org/1999/xhtml" displayBlock="true">

number="{ parts: [{path: 'invoice>ExtendedPrice'}, {path: 'view>/currency'}], type: 'sap.ui.model.type.Currency', formatOptions: { showMeasure: false } }"

unit="{view>/currency}" state="{= ${invoice>ExtendedPrice} > 50 ? 'Error' : 'Success' }"/>

and the controller contains this function (I am only pasting the part that works):

addRow: function() {

var oList = this.getView().byId("ins");

var oDt = oList.getBinding("items").getModel().oData;

}

However, I am not sure how to proceed. I have tried push() in the model, but I am getting errors. What I was thinking of doing now is to add an empty row in oDt and bind it to the table, but I am not sure how to proceed with this, and whether it is the optimal solution.

EDIT: How to Add a New ColumnListItem to a Table was marked as potential duplicate. This question is on the same topic, but the approach of the OP does not seem to match my use case (I am new to SAPUI5, so I might be wrong - in which case, please forgive me).

解决方案

this.getView().getModel('invoice').getProperty('/Invoices').push({/* new invoice data */})

this.getView().getModel('invoice').create('/Invoices', {/* new invoice data */})

or

this.getView().getModel('invoice').createEntry('/Invoices', {/* new invoice data */})

this.getView().getModel('invoice').submitChanges();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值