Skip to Content
avatar image
Former Member

How to solve attachRequestCompleted event getting called infinite in odatamodel v.2 ?

onPressBtn : function(){
	var oModel = this.getModel();
	var oModel2 = this.getModel();
	
	oModel.read("/Orders",{
		success : function(oData){
			console.log("Orders");
			console.log(oData.results);
		},
	        error : function(oData){
		        console.log(oData);
		});
					
		oModel.attachRequestCompleted(function(oData){
		     oModel2.read("/Employees",{
			success : function(oData){
			    console.log("Employees");
			    console.log(oData.results);	
		        },
			error : function(oData){
			    console.log(oData);	
			}
		      });
		});
},
Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Feb 19, 2017 at 03:16 AM

    Hello Siddharth,

    As expected the oModel2.attachRequestCompleted() gets into infinite loop. Is there a specific reason you place that in event handler of request completed ??

    onPressBtn : function()
    { 
       var oModel = this.getModel(); 
       var oModel2 = this.getModel(); 
       oModel.read("/Orders",
                  { 
                      success : this.readOrders.bind(this), 
                      error : function(oData){ console.log(oData); }); 
    },
    readOrders : function(oData,oResponse){
        this.getModel().read("/Employees",
              { success : function(oData){ 
                      console.log("Employees"); 
                       console.log(oData.results);	
              }, error : function(oData){ console.log(oData);	} });
    },
    

    This ensures that the second call happens on the success of first call. Does this handle your scenario?

    Thanks and Regards,

    Veera

    Add comment
    10|10000 characters needed characters exceeded