Skip to Content

XML Model Databinding Problem

Hello,

i get an Xml File through XML request which contains several ItemCodes.

After reading and assigning the data to the model i get at least 3 + entries.

var sXML =  oRequest_Item.responseText.substring(oRequest_Item.responseText.search("<GetProdSolutionsResult>"));

      sXML = sXML.substring(0, sXML.search("</GetProdSolutionsResult>"));

    

      

      oitem_Model.setXML(sXML);

            sap.ui.getCore().setModel(oitem_Model, "Item");

                    

            var test =oitem_Model.getProperty("/Solution/0/ItemCode" );

                     alert(test);

                      test = oitem_Model.getProperty("/Solution/1/ItemCode" );

                     alert(test);

                     test =oitem_Model.getProperty("/Solution/2/ItemCode" );

                     alert(test);

                     test =oitem_Model.getProperty("/Solution/3/ItemCode" );

                     alert(test);

My problem is i need to assign this model to an sap.m.Select

new sap.m.Select({

  editable : false,

  // selectedKey : "{SolutionCode}",

  items : {

  path :  "Item>/Solution/ItemCode",

  template : new sap.ui.core.Item(

  {

  text : "{Item>}",

  key :  "{Item>}"

  })

  },

   change : function(oEvent) {

   }

  }),  

If i do that i only get the first entry from the Itemcode in the Item model in the sap.m.Select listed. Not all itemcode entries that exist in the model.

Can someone tell me what in this binding is wrong?

Best regards

Dirk

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Oct 27, 2015 at 02:58 PM

    Hi Dirk,


    var oModel = new sap.ui.model.xml.XMLModel();

        oModel.loadData("your.xml", "", false);

        sap.ui.getCore().setModel(oModel, "Item");


    // Model Structure Example

    ---Solution{ //Level 1

         ---ItemCode : [{ // Level 2

              "Mytext" : "1",

              "MyKey"  : "09"

    }]

    }


    new sap.m.Select({

       editable : false,

       items : {

      path :  "Item>/Solution/ItemCode",

      template : new sap.ui.core.Item(

      {

      text : "{Item>Mytext}",

      key :  "{Item>MyKey}"

      })

      },

       change : function(oEvent) {

       }

        }), 

    Could you please tell me what are the data/structure available in "Item" Model.

    Run your Application---->Go to Console--->write sap.ui.getCore().getModel("Item"); -----> share with us

    Thanks,

    KA

      

    Add comment
    10|10000 characters needed characters exceeded

    • Hello Karthik,

      i soleved most of the problems but have one left.

      I need to find out how many entries are in the XML Model.

      I can see in the debugger that there are

      32 rows under

      Model.mContexts

      but i cant determine that number by runtime.

      If i assign

      var Data = mContexts

      then i have an Object with 32  object rows but i cant get the amount of rows.
      Can you or somebody else tell me how its determined?

      Best regards

      Dirk