Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3354

How to implement suggestions on sap.m.Input using xml model ?

$
0
0

Hi I am working on live suggestions when I type in an sap.m.Input the value entered will be used to fetch data from mysql db using a java servlet . The results are returned in the form of xml.

 

Below is the code for the sap.m.Input in the view ,

 

   var suggestItem = new sap.ui.core.Item(this.createId("item"),{

        text:"text()"     

        })

  

var inputUser = new sap.m.Input(this.createId("idUser"),{

            placeholder: "{i18n>userid}",

            type:"Number",

            showSuggestion:true,

            suggest:[oController.showSuggestion, oController]

        }).addStyleClass("inputPadding").bindAggregation("suggestionItems","/plants/plant_name",suggestItem)

 

This is the function in controller which gets called during suggest event

 

showSuggestion:function(oEvent){

 

  mthis = this

  if(!this.getView().byId("idUser").getModel("sample"))

  {

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

  this.getView().byId("idUser").setModel(sModel,"sample")

  }

 

var xml = sampleXml(this.getView().byId("idUser").getValue())

 

  ws_sample(xml,function(msg){

  xmldoc = jQuery.parseXML(msg);

  console.log(xmldoc)

  mthis.getView().byId("idUser").getModel("sample").setData(xmldoc)

 

})

}

 

the xml document from server will look like this

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<sample>

    <plants>

        <closed>0</closed>

        <district_id>0</district_id>

        <plant_id>7777</plant_id>

        <plant_name>xyz</plant_name>

    </plants>

    <plants>

        <closed>0</closed>

        <district_id>0</district_id>

        <plant_id>7778</plant_id>

        <plant_name>abc</plant_name>

    </plants>

    <plants>

        <closed>0</closed>

        <district_id>0</district_id>

        <plant_id>7779</plant_id>

        <plant_name>ghi</plant_name>

    </plants>

</sample>

 

I am trying to populate the suggestion items using the plant_name.

 

FYI I am setting the xml document to the sap.m.Inputs model , not the xml string.

 

there are no errors while running this code however no suggestion comes when I type.

 

Any sort of help will be much appreciated.

 

TIA.


Viewing all articles
Browse latest Browse all 3354

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>