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 sosubMenuModel.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
@
function backButtonClicked() {
for (var i = 0; i < previousMenu.count; ++i)
{
previousMenu.remove(i)
subMenuModel.iName = previousMenu.get(i).name// want an if i = null
// do something here like change the state of the back button to disabled
}
}
@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 dosomethinghow can i achieve this ?
-
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.
-
yes thats why im trying to make it stop at null and if null change the state of my back button to disabled
-
any solutions ?
-
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?