cancel
Showing results for 
Search instead for 
Did you mean: 

sapui5 how to make odata data to array

Former Member
0 Kudos

i wan to manipulate odata data,so I want to make the odata to array to manipulate.For example i want to check the key data i inseted whether repetition.

i want to make odata data to array,but i don`t binding list or table .i just want to operate it in controller.

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member484715
Contributor
0 Kudos

Whenever you read from odata, the output you get is in the form of array of objects.

this._model.read("/yourEntitySet",null,null,false,function(oData){
			console.log(oData.results); //oData.results is an array		
	});
Former Member
0 Kudos
oModel.read("/EntitySet", { 
success: function(oData){ //here you can assign the data to your array from the oData parameter } });
Former Member
0 Kudos

could you give me the example? i am newer and i don`t how to write the code

Former Member
0 Kudos

Hello Jingquan,

you need to define your oData model in your controller and then you can call your service inside that model.

var sServiceUrl = "/sap/opu/odata/sap/OData_proj_name_SRV"; //OData_proj_name_SRV is your odata srv project name

var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);

oModel.read("/EntitySet",{

sucess:function(oData){

console.log(oData).

//here you can see your odata service output in console prompt of you browser. Accordingly you can modify that based //on your requirement.

}

});

0 Kudos

Just for correctness reason there is a mistake in the comment above (Apr 14, 2017 at 10:30 AM).

At

console.log(oData).

there should be a semicolon instead of the dot!

console.log(oData);

This should be correct, for a beginner like me it took me 10 minutes to find this mistake.

Best regards.