Selecting tab in TabView


Trying to get my app to go to a particular tab based on some program logic.
Trouble is that I can’t do a getViewById(“TabView”) from within a tabbed page - it’s as though the page doesn’t contain the tabview (which is reasonable), but I can’t do page.parent.getViewById either.
What’s the trick?


<TabView [selectedIndex]=“currentIndex” >

i hope this will help you.


As simple as that?! Will try…


Doh, just realised that you were giving me XML markup! No - I’ve got that. I just want to be able to change the tab dynamically under program control.


XML is just a form of actual JavaScript class. You can of course use the same property in JavaScript / TypeScript etc.,

If you have difficulty in accessing your TabView, we may able to help only if we know your app’s UI hierarchy. May be you can try creating a playground example.


Good idea - would a public project on github be a good way to share this?


Playground could be the best option, still shareable and public. Doesn’t need a local setup and complication so anyone can take a quick look.


Mmmm. Very clever, but it seems that it’s really hard to upload an existing project.
NativeScript Sidekick can create a basic TabbedApp in the blink of an eye which has 99% of what I’d like to put into the playground, but unless I’m missing something, it would take quite a long time to upload to playground?


I have got a solution here, actually, which is to use data-binding and a model view to dynamically set the value of selectedIndex. It’s amazing what can be done with data-binding… :wink:

Also, I think my attempts to navigate the DOM were based on the false premise that the tabView would be in the parent of the page. Actually the tabView contains frames which contain pages, so one would need to backup the ancestry a bit more. However, I think the data-binding method is more elegant.