Home javascript android java php c# ubuntu python c++ c ios TAGS

Cannot read property length of undefined


Date : 2019-04-30 15:47:31 , By : sohail ahmed

When i am writing the below code in my onInit Function of WEBIDE, i am getting this error.

Cannot read property length of undefined.

But when i am writing the code inside my press event of button then its working fine.

var i;
var oMod = sap.ui.getCore().getModel();
var itab = oMod.getProperty("/empTab");
for (i = 0; i < itab.length; i++) {
  if (itab[i].empName === 'Sohail') {
    itab[i].Smoker = false;
    oMod.setProperty("/empTab", itab);
  } else {
    itab[i].Smoker = true;
    oMod.setProperty("/empTab", itab);
  }
}
TAGS : javascript
Answers :

Probably you have the exact same issue as below

Component + default OData model: this.getView().getModel() returns undefined in onInit() of controllers

Use

this.getOwnerComponent().getModel() 

Inside your onInit function as the global model is still not recognized during this lifecycle stage of your view.

- Technology - Yellow pages
» java
» php
» c#
» ubuntu
» python
» c++
» c
» ios
» jquery
» html
» sql
» r
» mysql
» linux
» access
» iphone
» css
» excel
» vb.net
» .net
» ruby
Privacy Policy - Copyrights Notice - Terms - Contact Us 2019 © tinytut
Licensed under cc by-sa 3.0 with attribution required.