Skip to Content
-2

UI5 Binding to global model

At present we have a global model (GM) defined in our /model area and then loaded via the manifest. This model is available via the XML view and using .getModel/.getProperty is also available to the view controller as well.

Out current practice is to get the required data from the global model for a specific property path (GM>/contacts/Insurance) , and then create a model from that and bind it to view table control, by ID. The view table then has access to the data in the global model. However, I believe this is the wrong approach, as I don't think it will update the global model (two way) when we Insert/delete rows in the View table, due to the way we have bound a new model to the view table, or am I incorrect?.

Ideally, What I would want to do is hard code the XML view control like so:

<Table items="{GM>/contacts/Insurance}" ...

Where GM is out global model, and the View table points to the array /contacts/Insurance of the json model.

Within the view table control we use buttons to call functions when we need to Insert/Delete rows. As the XML view has the binding hard-coded to "{GM>/contacts/Insurance"} how can I get back the binding being used, without physically having it hard-coded in the controller functions?. Is that possible.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Apr 04, 2017 at 02:19 PM

    have u done anything?

    just bind to the path, nothing else. if you are using jsonmodel

    Add comment
    10|10000 characters needed characters exceeded

    • no need local model, just bind to global one.
       var lgm = this.getOwnerComponent().getModel("GM");
      
      var tabledata=lgm.getProperty("/contacts/insurance");
      tabledata.push(newrecord);
      
      lgm.setProperty("/contacts/insurance",tabledata);
      
  • Apr 04, 2017 at 06:51 PM

    Hi,

    Do I understand you correct and are you using the same global model in your table in the view? Then it should just work. But you'll have to active TwoWay binding in the manifest.json.

    Kind regards,

    Wouter

    Add comment
    10|10000 characters needed characters exceeded

    • Two-way binding is the default for a json model, I believe.

      As I have just mentioned to Jun, my problem is not in binding my View table to a global mode, or updating it, the problem is how I can get my controller Insert/delete functions to work so that they can insert/delete rows from my view table. I have given code examples in my reply to Jun.