Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9159

Re: why am i getting Uncaught TypeError: Cannot read property 'setData' of undefined ,please tell the solution

$
0
0

Hi Raghu.

 

The variable categoryModel1 doesn't exist in the success function context when it's called.

You have to get your model inside the success function.

 

 

 

//Get model for category     var categoryModel1= sap.ui.getCore().getModel("categoryModel");     // service url     var  serviceUrl= oApplication.appData.serviceUrlRoot +"/rest/categories";     //call ajax method     jQuery.ajax({         type : "GET",         contentType : "application/json",         url :  serviceUrl,         dataType : "json",         //on success:set data to  the category field         success : function(data,textStatus, jqXHR) {             console.log(data);             var categoryModel1 = sap.ui.getCore().getModel(); // Get the model for this context             categoryModel1.setData({                 items :data               });             },         error : function(jqXHR,textStatus,errorThrown) {             raiseWebserviceException(jqXHR);           }     });

 

 

PS: you don't need to call the AJAX routine like you did. I changed it in the example, but if you want to use like you did before, no problem it'll work too.


Viewing all articles
Browse latest Browse all 9159

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>