0

I currently work on a UI5 project which loads data from a local .json and bind it to a model. I can now edit and add new values to the model.

Is it possible to export this modified model as .json through a file download dialog?

I'm new to UI5 and looked on serveral posts but only found export to CSV where columns and rows are set. But this does not fit my case. I need it just converted back to .json.

Hopes anyone has an idea.

kynie
  • 85
  • 1
  • 9

1 Answers1

0

UI5 does not have a Control for this, but you can use sap.ui.core.HTML and trust the functionality of < a >-Tag

<!DOCTYPE HTML>
<html>
 <head>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta charset="utf-8">
  
  <title>Just a Button</title>
  
  <script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" 
   id="sap-ui-bootstrap"
   data-sap-ui-libs="sap.ui.core" 
   data-sap-ui-theme="sap_belize"></script>
   <!-- only load the main library "sap.m" and the Belize theme -->
  
  <script>
   var json = {"My":"Json","is":"cool"};
   var data = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(json));
   
   var btn = new sap.ui.core.HTML({
    content:"<a href='data:"+data+"'  download ='data.json'>Download Json</a>" 
   });
   btn.placeAt('content');
  </script>
  
 </head>
 <body id="content" class="sapUiBody">
 </body>
</html>
A.vH
  • 881
  • 6
  • 10