Skip to Content
0

Pass data from detail view to Master view SAPUI5

Jan 24 at 08:32 PM

66

avatar image

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);
});
wanted.png (32.6 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Emanuele Ricci Jan 25 at 09:19 AM
0

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);
Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Jan 24 at 08:55 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Efim Parshin Jan 25 at 08:24 AM
0

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});
}
Share
10 |10000 characters needed characters left characters exceeded