Skip to Content
1
Former Member
Oct 24, 2015 at 05:19 PM

Change model in XML-template.

72 Views

Hi!

Please help understand the problem!

I learned XML templates. Following the example of 'XML Templating in SAPUI5', I create a view and places it in the main view.

Main.controller.js

//...
var o_goals_data_model = new JSONModel(this.goals_data);
var o_settings_model = new JSONModel(this.settings);


var o_form_view_template = sap.ui.view({
  preprocessors: {
  xml: {
  models: {
  goals_data: o_goals_data_model,
  settings: o_settings_model
  }
  }
  },
  type: sap.ui.core.mvc.ViewType.XML,
  viewName: 'sap.app.GoalSet.view.Form'
});
this.getView().byId('goalset_main_shell').addContent(o_form_view_template);
//...

However, the controller can not I turn to the model in view. If I need to change the model, how it can be done?

Form.controller.js

ap.ui.define( ["sap/ui/core/mvc/Controller"], 
  function (Controller, History, JSONModel) {
  "use strict";


  return Controller.extend("sap.app.GoalSet.controller.Form", {


  onInit : function () {},

  onTogleEditTables: function(){

  var o_view = this.getView();                                    //OK
  var o_model = o_view.getModel("settings");           //undefined
  var status = o_model.getProperty("/edit_tables");   //Error!

  //o_model.setProperty("/edit_tables", !status);        //???
  sap.m.MessageToast.show(status);
  },
  });
});

Sorry for my English ... I hope my problem is clear.