May 17, 2012

Alcatraz Alcatraz
Lab Rat
25 posts

TypeError: Result of expression ‘previousMenu.get(i)’ [undefined] is not an object.

 

im getting a little lost on why this is happening to me

if i do console.log(“Text = “+ previousMenu.get(i).name)
works shows me the text but when i try to pass on that value to another qml like my other model like so

subMenuModel.iName = previousMenu.get(i).name

i get the error

TypeError: Result of expression ‘previousMenu.get(i)’ [undefined] is not an object.

show you the code

  1.     function backButtonClicked() {
  2.         for (var i = 0; i < previousMenu.count; ++i)
  3.         {
  4.             previousMenu.remove(i)
  5.             subMenuModel.iName = previousMenu.get(i).name
  6.  
  7.   // want an if i = null
  8.   // do something here like change the state of the back button to disabled
  9.         }
  10.     }

every item thats clicked gets appended to a listmodel then what i want to do is remove the LAST one in the list ie i = 1 remove 1 get 0
if i is null dosomething

how can i achieve this ?

4 replies

May 17, 2012

vulee vulee
Lab Rat
11 posts

If i is the index of the last item in the list, previousMenu.remove(i) would remove the last one, then previousMenu.get(i) would return undefine.

May 17, 2012

Alcatraz Alcatraz
Lab Rat
25 posts

yes thats why im trying to make it stop at null and if null change the state of my back button to disabled

May 23, 2012

Alcatraz Alcatraz
Lab Rat
25 posts

any solutions ?

May 24, 2012

mlong mlong
Robot Herder
1551 posts

I’m not sure exactly what you’re trying to do.

If you’re trying to do something for all elements and then do something special with the last one, why not loop from 0 to count-1, then handle the special case of the last item on it’s own?

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

 
  ‹‹ N9 virtual keyboard feedback effect      QML dependencies??? ››

You must log in to post a reply. Not a member yet? Register here!