Search code examples
javascriptxmldata-bindingsapui5

How can I use complex binding to get keys displayed rather then values from key value pairs in view.xml


I know I can use complex binding to display values using keys from my model. Which is json object. But how can i print all the keys without knowing how many of them are there.

I tried searching for the solution in google but nothing similar is present.

<f:Form id="SimpleFormDisplay354" editable="true">
   <f:toolbar>
      <OverflowToolbar design="Transparent">
         <Title text="Details" level="H2"/>
         <ToolbarSpacer/>
         <Button icon="sap-icon://decline" press="handleSideContentHide"/>
      </OverflowToolbar>
   </f:toolbar>
   <f:layout>
      <f:ResponsiveGridLayout/>
   </f:layout>
   <f:FormContainer>
      <f:formElements items="{path: '/'}">
         <f:FormElement label="{label}">
            <f:fields><Input placeholder="Send Text" type="Text" width="50%"/></f:fields>
         </f:FormElement>
      </f:formElements>
   </f:FormContainer>
</f:Form>

I want to know what should I be writing instead of {label} to display keys.


Solution

  • What I did to solve my problem is I dynamically added the elements in my formContainer using my controller.js.

    for (var key in oValues) {
    
         if(oValues.hasOwnProperty(key)){
               var oFormElement = new sap.ui.layout.form.FormElement().addField(new sap.m.Input({value:oValues[key]}));
               oFormElement.setLabel(key);                                                               
               this.byId("id_of_FormContainerinXML").addFormElement(oFormElement);
                 }
       }