SAPUI5 SAPUI5 XML model add item

一世执手 提交于 2019-12-23 05:08:30

问题


I have an XML model bound to a table and I want to add a new row to the model. The XML data itself is rather simple:

<gettagevents>
<tageventlist>
    <tagevent>
        <time>2011-09-09T14:29:16.302Z</time>
        <factory>06</factory>
        <materialcode>21</materialcode>
        <serial>16999991231</serial>
    </tagevent>
    <tagevent>
        <time>2011-09-09T14:29:17.101Z</time>
        <factory>06</factory>
        <materialcode>21</materialcode>
        <serial>16999991232</serial>
    </tagevent>
</tageventlist>

Only relevant is the value for serial, so it would be enough for me to add a new serial number to the model. I have read about document.createElement, which I guess could work for me, but I do not get it working.

I have this part in my controller:

var oTable = this.getView().byId("tbl_det3_rfid");
var oSerial = "1234567890";
var oModel = oTable.getModel();
var aData = oModel.getProperty("/tageventlist/tagevent/serial")

Can anyone help me how to get this done, so adding a new line to my model with the serial e.g. 1234567890?

Thanks,

Tim


回答1:


I don't think the XML Model control allows you to add a new record. However you could get the XML object from the model and append a XML node to it using jQuery. After this you would have to update the model to see the new node in the table.

var oXML = oModel.getObject("/tageventlist");
$(oXML).append("<tagevent><time>2011-09-09T14:29:16.302Z</time><factory>06</factory><materialcode>21</materialcode><serial>16999991236</serial></tagevent>");
oModel.refresh(); 


来源:https://stackoverflow.com/questions/42898699/sapui5-sapui5-xml-model-add-item

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!