cancel
Showing results for 
Search instead for 
Did you mean: 

Populating combobox from oData service.

0 Kudos

Hi Guys,

             I am trying to populate Combobox in my Fragment pop-up from oData service.

Model.Js

getPlantModel: function(vController, entitySet, filter, modelName) {

  var mainDataModel = this.mainDataModel();

  var oModel = new sap.ui.model.json.JSONModel();

  mainDataModel.read(entitySet+filter, {

  success: function(data, response) {

  oModel.setData({

  listitems: data.results

  });

  /* vController.getView().setModel(oModel, modelName);*/

  },

  error: function(oError) {

  vController.getView().setModel(oModel, modelName);

  /*do nothing yet return empty model*/

  }

  });

  },

View.Controller.js

var vController = this;

  var qryFilter = "";

  this.router = sap.ui.core.UIComponent

  .getRouterFor(this);

  this.router

  .attachRoutePatternMatched(

  this._handleRouteMatched,

  this);

  // Bundle F4 Help

  // qryFilter = "?$filter=IvBundle eq 'X' and IvEqunr eq ''&$format=json";

  models.getPlantModel(vController,

  'ETS_PLANT', qryFilter,

  "plantF4Model");

  var oItem = new sap.ui.core.Item({

  text: "{Zzpname}",

  key: "{Zzwerks}"

  });

  var oComboBox = this.getView().byId("plantComboBox");

  oComboBox.bindItems("plantF4Model", oItem);

--------------------------------------------------------------------------------

When I try to get reference to Combobox.. t

var oComboBox = this.getView().byId("plantComboBox");


oComboBox returns undefined.


any idea how this can be solved.



Thanks

Sam


Accepted Solutions (0)

Answers (1)

Answers (1)

saivellanki
Active Contributor
0 Kudos

Hi Sam,

Are you using JS View  / XML View?

If it is JS View, how did you define the combo box id?

Just a guess, did you tried like this as well?


sap.ui.getCore().byId("plantComboBox");

Regards,

Sai Vellanki.

0 Kudos

Yes I did.. without any success.

Now I am trying to set the model and bind it like this.

// Populate Model

models.getDataModel(vController, 'ETS_PLANT', qryFilter, "plantF4Model");

// Binding Model

this.oPersonalizationDialog.setModel(this.getView().getModel("plantF4Model"),"plantF4Model");

Because I am biding in a combobox in Fragment.. that's why it's struggling..

Thanks

saivellanki
Active Contributor
0 Kudos

Oh, I missed the fragment word in your question , were you able to resolve it? or still it is not working?

Regards,

Sai Vellanki.

0 Kudos

Hi Thanks.. I am able solve it.. I have commented out semodel method in Model.Js.. that's why it didn't bring any value.

now I have read the selected item from Combobox.. if you have any sample code.. please let me know.

Thanks

Sam