cancel
Showing results for 
Search instead for 
Did you mean: 

Pass data from detail view to Master view SAPUI5

0 Kudos

I need to pass data from detail view to master view after selecting a checkbox as shown below.

on the detail controller I already have the checkbox function:

    estSelect: function(oEvent) {

var isSelected = oEvent.getParameter("selected");
var cxt = oEvent.getSource().getBindingContext();
var wordName = cxt.getObject("Word");

if (isSelected) {
cxt.getModel().setProperty("percent", "100%", cxt);
               this.updateSummary(wordName);
} else {
cxt.getModel().setProperty("percent", null, cxt);
}
}, 

I was trying to create a tree table with the data to the master view content:


    updateSummary: function(mName) {
var summaryLocation = sap.ui.getCore().byId("<masterContentLocation>");

var oModel = new sap.ui.model.json.JSONModel([{
title: mName,
children: [{
title: mName
}]
}]);

sap.ui.require([], function() {
var oTree = new sap.m.Tree({});
oTree.setModel(oModel);
var oStandardTreeItem = new sap.m.StandardTreeItem({
title: "{title}"
});
oTree.bindItems("/", oStandardTreeItem);
oTree.placeAt(summaryLocation);
});

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member233511
Participant

You can use EventBus for passing data between different controllers. For example:

Master controller (onInit):

var oEventBus = sap.ui.getCore().getEventBus();

function handleWordSelected(oData) {
    var oModel = //get your master model here
    var aItems = oModel.getProperty('/');
    aItems.push({title: oData.word, children:[]});
    oModel.updateBindings();
}

oEventBus.subscribe('wordSelected', handleWordSelected);

Detail controller (your checkbox select handler):

estSelect: function(oEvent) {
    var isSelected = oEvent.getParameter("selected");
    var cxt = oEvent.getSource().getBindingContext();
    var wordName = cxt.getObject("Word");

    if (isSelected) {
        cxt.getModel().setProperty("percent", "100%", cxt);
               this.updateSummary(wordName);
    } else {
        cxt.getModel().setProperty("percent", null, cxt);
    }    

    var oEventBus = sap.ui.getCore().getEventBus();
    oEventBus.publish('wordSelected', {word: wordName});
}
ericci
Active Contributor
0 Kudos

Here you have two options:

  • Update a value on a local JSON Model and listen to that edit in the master (overkilling maybe)
  • Use event bus to send/receive a message (I suggest this one)

Send a message (from detail to master):

sap.ui.getCore().getEventBus().publish(channel, event, data);

Subscribe (master)

sap.ui.getCore().getEventBus().subscribe(channel, event, handler, listener);

Unsubscribe (master)

sap.ui.getCore().getEventBus().unsubscribe(channel, event, handler, listener);
junwu
Active Contributor
0 Kudos

put them in model, which is shared to all view. no need to pass between each other....