Skip to Content
0
Jan 14, 2021 at 03:37 PM

Not able to bind JSON model to table - Cannot read property 'setModel' of undefined

177 Views

Hi,

Structure of my app:

Empty table with button at header which will open a dialog of simpleForm to fill student details and one click "Add", the input field entries has to be added in table.

Two fragments using. One is for table (imported the fragment in view) and another is for dialog (loaded the dialog fragment in controller file).

Dialog.fragment.xml:

<beginButton>
  <Button text="Add" type="Emphasized" press="onDialogAddRecord"/>
</beginButton>

Home.controller.js:

sap.ui.define(["sap/ui/model/json/JSONModel", func...
 
onDialogAddRecord: function (oEvent) {
   var Dfname = sap.ui.getCore().byId("inputFirstName").getValue();
   var Dmobno = sap.ui.getCore().byId("inputMobileNo").getValue();

   var oTable = sap.ui.getCore().byId("table");
   var studModel = new JSONModel();
   var studData = {
    fname: Dfname,
    mobile: Dmobno,
  };
 // set the data to JSON model and assigned path name
 studModel.setData({"students":studData});
 // binding model to table
 oTable.setModel(studModel);
 // closing the dialog
 this.oDialog.close();
} 

Table.fragment.xml:

 <Table id="table" items="{/students}">
   <columns>
     <Column>
       <Label text="Name"/>
     </Column>
     <Column>
       <Label text="Contact Number"/>
     </Column>
   </columns>
   <items>
     <ColumnListItem >
       <cells>
         <Text text="{fname}"/>
         <Text text="{mobile}"/>
       </cells>
     </ColumnListItem>
   </items>
 </Table> 

After adding details, when i click ADD, i am getting an error as setModel is undefined. Attached the error screenshot below for your reference.


Attachments

xhitsvpu2m.png (62.3 kB)