on 10-13-2015 11:57 AM
Hi everyone. The following works:
// Create JOSN Model Instance
var lco_JSM = new sap.ui.model.json.JSONModel();
// Create JSON
lco_JSM.setJSON(
'{ "Data": [{"Title": "Mr.",' + '"FName": "John", "LName": "Doe"},'
+ '{"Title": "Mrs.", "FName": "Jane", ' + '"LName": "Doe"}]}');
// Bind Model To Core
sap.ui.getCore().setModel(lco_JSM);
While this doesn't work:
// Create JOSN Model Instance
var lco_JSM = new sap.ui.model.json.JSONModel();
// Sample JSON Data
var lcs_Data =
{ "Data":
[ { "Title" : "Mr.",
"FName" : "John",
"LName" : "DOe" },
{ "Title": "Mrs.",
"FName": "Jane",
"LName": "Doe" }
]
};
// Create JSON
lco_JSM.setJSON({'lcs_Data'});
// Bind Model To Core
sap.ui.getCore().setModel(lco_JSM);
I get a syntax error. Alternatively when I load the JSON file the same set of data works, But right now, I'm getting a syntax error when I use JSON data residing in a variable.
Thanks in advance.
Hi,
why are you passing in lco_JSM.setJSON({'lcs_Data'}); the Ics_Data variable in JSON format again. The variable contains the JSON.
Change your coding to Ico_JSM.setJSON(Ics_Data);
Best Regards,
Florian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually I was playing around and "lco_JSM.setJSON(lcs_Data);" was not working hence I added the the quotes. But when I use "lco_JSM.setJSON(lcs_Data);", it gives me a syntax error during debugging. There are plenty of source online that use this method, but I still don't get why I'm getting a syntax error. PS: I didn't realize I pasted the wrong section!
This is the actual code that doesn't work:
// Sample JSON Data
var lcs_Data =
{ "Data":
[ { "Title" : "Mr.",
"FName" : "John",
"LName" : "DOe" },
{ "Title": "Mrs.",
"FName": "Jane",
"LName": "Doe" }
]
};
// Create JOSN Model Instance
var lco_JSM = new sap.ui.model.json.JSONModel();
// Create JSON
lco_JSM.setJSON(lcs_Data);
Hi Jibran,
It should be lco_JSM.setData(JSON.stringify(lcs_Data)) , try this -
// Create JOSN Model Instance
var lco_JSM = new sap.ui.model.json.JSONModel();
// Sample JSON Data
var lcs_Data =
{ "Data":
[ { "Title" : "Mr.",
"FName" : "John",
"LName" : "DOe" },
{ "Title": "Mrs.",
"FName": "Jane",
"LName": "Doe" }
]
};
// Create JSON
lco_JSM.setData(JSON.stringify(lcs_Data));
// Bind Model To Core
sap.ui.getCore().setModel(lco_JSM);
Since, setJSON method expects string data.
API - JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.json.JSONModel
Regards,
Sai Vellanki.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
Try this
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData({
modelData: arraydata
});
sap.ui.getCore().setModel(oModel);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.