Quantcast
Channel: SCN: Message List - SAPUI5 Developer Center
Viewing all articles
Browse latest Browse all 8124

How to send child view instance, on click of child view to parent Controller method

$
0
0

Hi All,

 

I have child views. In click event of child view, I have to call parent controller method which also send child view as parameter. How to do this.

 

In Parent View

I had following code

 

for(var j=0;j<oModel.oData.Groups[i].Products.length;j++)

                                        {

                                        var product = sap.ui.view({

                                            viewName : "MyApp.product",

                                            type : sap.ui.core.mvc.ViewType.JS

                                        });//Created Child View

                                        product.bindElement("/Groups/"+i+"/Products/"+j);

                                        product.attachBrowserEvent("click", function(event){

                                            oController.SelectionChange(event,product);

                                            });//Child view click event

                                        oLayout.addContent(product);

                                        }

 

In Controller
SelectionChange: function(event, view)

{

//here 'view' is always last object in for loop above. But I want it should be that object which was clicked
   if(view.IsSelected)

  {

view.removeStyleClass("selected"); //Always remove last element style

  }

else

{

view.addStyleClass("selected");//Always set last element style

}

}


Viewing all articles
Browse latest Browse all 8124

Trending Articles



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