cancel
Showing results for 
Search instead for 
Did you mean: 

XML Model Databinding Problem

dirk_wieczorek
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

karthikarjun
Active Contributor
0 Kudos

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

  

dirk_wieczorek
Participant
0 Kudos

Hello Karthik,

i dont know if that is waht you need.

I made a screenshot from the model in the console.

If its wrong please let me know.

My problem is the select only shows the first entry from the model.

karthikarjun
Active Contributor
0 Kudos

I think there is some problem in your xml structure. Because first entry it is showing the path and its details, but 8 entry was not showing path details.

Check with your xml structure or better go with json approach, it is crystal clear to understand the structure of your data

Thanks,

KA

dirk_wieczorek
Participant
0 Kudos

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

Answers (0)