0

I have a JSON model /details with 4 objects. I want the object based on the key :month.

   Object
   oData
   details:
   Array[4]
   0:Object
   1:Object
   2:Object
   3:Object
    editable:false
    key:"date"
    removeable:false
    value:"Day: TRUE, Night:False"
   4:Object
    editable:false
    key:"month"
    removeable:false
    value:"August"

The following is the code

/view

 var viewModel = that.getView().getModel();
 var viewModelData = viewModel.getData();
3

1 Answer 1

1

You cannot query the object directly. You have to loop and search like so:

var viewModel = that.getView().getModel();
var viewModelData = viewModel.getProperty("/details");
var month = getObjectByKey(viewModelData, "month");

function getObjectByKey(a, key){
  for(var i = 0; i < a.length; i++){
  if (a[i].key === key){
    return a[i];
  }
  return null;
}
Sign up to request clarification or add additional context in comments.

4 Comments

I get the model with the property, but I am not able to bind it.sap.m.Table({ columns: [ new sap.m.Column({ header: new sap.m.Text({ text: 'key',. }) }),], items: { path: '/details', template: new sap.m.ColumnListItem({ cells: [ What should be the path for binding to table
What do you want to achieve? Do you want to have a table with each detail object as row displaying their key and their value? Or do you want to display an array contained in the key="month" object in the table?
I want to display each detail object with key = "month" as row displaying their key and their value
I have made a new question stackoverflow.com/questions/41448141/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.