cancel
Showing results for 
Search instead for 
Did you mean: 

How will I bind more json model in my view ?

0 Kudos

I'm trying to get data in java servlet but when I get new data from the servlet, it's overwriting the existing model. May I bind more json model to my view and how will I do this ?

sap.ui.define( [ "jquery.sap.global", "sap/ui/core/Fragment",
"sap/ui/core/mvc/Controller", "sap/ui/model/Filter",
"sap/ui/model/json/JSONModel" ], function(jQuery, Fragment, Controller,
Filter, JSONModel) {
"use strict";
return Controller.extend("sap.ui.demo.wt.controller.Form", {
     onInit : function() {
         this.getData();
         var data = {
             material_unit : [],
             material : []
         };

         var oModel = new sap.ui.model.json.JSONModel();
         oModel.setData(data);
         sap.ui.getCore().setModel(oModel);
      },
      getData : function() {
          $.ajax( {
             data : "",
             type : "post",
             dataType : "json",
             async : false,
             contentType : "application/json; charset=UTF-8",
             url : "/material_process/OperationServlet?action=UNIT",
             success : function(returnData) {
                var material_unit = new sap.ui.model.json.JSONModel();
                material_unit.setSizeLimit(returnData.length);
                material_unit.setData( {
                    units : returnData
                });
                sap.ui.getCore().setModel(material_unit);
             },
            error : function(jqXHR, textStatus, errorThrown) {}
       });
      },
handleLiveChange : function(oEvent) { var value = oEvent.getParameter("value"); $.ajax( { data : "", type : "post", dataType : "json", async : false, contentType : "application/json; charset=UTF-8", url : "/material_process/OperationServlet?action=MATSEARCH-"+ value, success : function(returnData) { var material = new sap.ui.model.json.JSONModel(); material.setData( { materials : returnData }); sap.ui.getCore().setModel(material, "material"); }, error : function(jqXHR, textStatus, errorThrown) {} }); } }); });

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member484715
Contributor

Hi Serdar Yazıcı,

You can use any number of models in your view with the help of different aliases.

this.getView().setModel(oModel,"Your_Alias_Name");

Regards,

Arjun Biswas

SergioG_TX
Active Contributor
0 Kudos

the issue you are having is bc you are binding the entire data model w the new data set, instead, you should add the data set to a model property - then get/set it... if you need to add more properties, then "set" the new property and its value. if you google... add property to json model you'll find a lot of examples