cancel
Showing results for 
Search instead for 
Did you mean: 

removed......

former_member489109
Participant

Accepted Solutions (1)

Accepted Solutions (1)

nicoschoenteich
Developer Advocate
Developer Advocate
0 Kudos

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)
former_member489109
Participant

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;
		},

Answers (2)

Answers (2)

junwu
SAP Champion
SAP Champion
0 Kudos

why you are doing that? what is the real problem?

if you delete it, how can it be json format???

former_member489109
Participant
0 Kudos

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").

ThorstenHoefer
Active Contributor
0 Kudos

Hi Burak,

what is about this approach.

this.getModel().read("/MyEntity",{
success(oData){
var _oPerson = oData.result; var _nameFirst = _oPerson.FirstName; ... } });
former_member489109
Participant
0 Kudos

Hi Thorsten,

Thank you for your answer.I know how to reach this elements inside json. My problem is not that. My purpose is deleting the "results" tags from the returned odata json by dynamically. So I want the converted json does not have any result tag at the end

ThorstenHoefer
Active Contributor
0 Kudos

Hi Burak,

you can create a new Json String with


oData.result.Education = oData.result.Education.result;
JSON.stringify(oData.result)