SAPUI5 get single property from JSON-Model -
I am currently trying to figure out how I got a sap.ui.model.json.JSONModel
In my main view:
var gConfigModel = new sap.ui.model.json.JSONModel (); Var getConfigCallback = function (config) {gConfigModel.setData (config); }; OController.getConfiguration (getConfigCallback); Console.log (gConfigModel); In my controller:
getConfiguration: function (callback) {var sServiceUrl = "/ sap / opu / odata / sap / xxx / configurationSet (' Start ') "; Var config = {}; Callback; $ .getJSON (sServiceUrl) .done (function (data) {config = data.d; callback (config);}); }, In your console.log statement, I can see that the data passed from the backend successfully and successfully set to the JSON model. The value of my requirement attribute is editable in a variable.
I already have gConfigModel Tried .getProperty ('/'), did not work. Attempted to use GConfigModel.oData .. How can I store it in a value?
Solution Comment: If you capture data from backend, then you have to remember how long it will take. The data can later be available, hopefully in my case I added a 1 second timeout, later I can easily use the property setTimeout (function () {console Log (gConfigModel.getProperty ('/ editable'));}, 1000);
& lt; Script src = "https: // Openui5.hana.ondemand.com/resources/sap-ui-core.js" id = "Sap-U-Bootstrap" Data-SAP-UI-Theme = "SAP_blueistrist" Data-SAP- UI-Libs = "SAPM"> & gt; & lt; / script & gt; & lt; script & gt; function getConfiguration (callback) {var sServiceUrl = "/ sap / opu / odata / sap / xxx / configurationSet ('Initialize') "; var config = {}; Var data = {" d ": {" _metadata ":" "," backup "": "01", "editable": "true"}}; SetTimeout ((function () {config = data; callback (config);}) (), 2000); }; Var gConfigModel = new sap.ui.model.json.JSONModel (); Var getConfigCallback = function (config) {gConfigModel.setData (config); Warning (gConfigModel.getProperty ("/ d / editable")); }; GetConfiguration (getConfigCallback); & Lt; / Script & gt;
Comments
Post a Comment