Skip to Content
avatar image
Former Member

How will I bind more json model in my view ?

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) {} }); } }); });
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Dec 12, 2017 at 10:20 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 11, 2017 at 01:38 PM
    -2

    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

    Add comment
    10|10000 characters needed characters exceeded