on 2021 Nov 22 2:09 PM
Request clarification before answering.
Hi Burak,
I gave it a go and came up with this rather ugly solution. It works for a maximum of two nested result-arrays inside the top-level result array. I guess you know the kind of response you will get so you will you can decide if two is enough or if you need more levels. You could more levels in a similar fashion as I did or spent some time on it and come up with some kind of recursive function.
if (a.result) var b = a.result
for (i = 0; i < b.length; i++) {
Object.keys(b[i]).forEach(key => {
if (b[i][key].result) b[i][key] = b[i][key].result
Object.keys(b[i][key]).forEach(key2 => {
if (b[i][key][key2] && b[i][key][key2].result) b[i][key] = b[i][key][key2].result
})
})
}
console.log(b)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yess!!
I also found a similar solution. Thank you very much!
_edit: function(oData) {
var aData = oData.results;
var aKeys = [];
for (var i = 0; i < aData.length; i++) {
aKeys = [];
aKeys = Object.keys(aData[i]);
for (var j = 0; j < aKeys.length; j++) {
if (aData[i][aKeys[j]] instanceof Object && aData[i][aKeys[j]].hasOwnProperty("results")) {
aData[i][aKeys[j]] = aData[i][aKeys[j]]["results"];
}
}
}
return aData;
},
why you are doing that? what is the real problem?
if you delete it, how can it be json format???
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Firstly you can see my odata picture then;
If you try this like deep insert you will get error.Because deep insert works without "results" tags.
var oEntry = oData.results[0];
var oModel = that.getView().getModel();
oModel.create("/ScarrSet", oEntry, {
method: "POST",
success: function(oData, oResponse) {
console.log("success");
},
error: function(oError, oResponse) {
console.log("error");
}
});
But if you remove "results" tags its work fine
var oEntry = oData.results[0];
oEntry.ScarrToSpfli = oEntry.ScarrToSpfli.results;
oEntry.ScarrToSflight = oEntry.ScarrToSflight.results;
var oModel = that.getView().getModel();
oModel.create("/ScarrSet", oEntry, {
method: "POST",
success: function(oData, oResponse) {
console.log("success");
},
error: function(oError, oResponse) {
console.log("error");
}
});
I know i can change data before create operation.I dont prefer this. I just want to remove all "result" tags in the returned odata json.
In addition, it provides convenience in data binding.
You can use it as ("test>/data") instead of ("test>/data/results").
Hi Burak,
what is about this approach.
this.getModel().read("/MyEntity",{
success(oData){
var _oPerson = oData.result;
var _nameFirst = _oPerson.FirstName;
...
}
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
65 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.