Search code examples
titaniumtitanium-mobileappceleratorappcelerator-mobile

How to get child objects of a window in titanium classic


I have window, in that there is a view with a table. Now how can I get that table object exists in window->view.

Thanks in Advance,

Swathi


Solution

  • Ok, this is actually fairly easy. However, there is no "direct" API call for it... But you can easily create one yourself.

    Basically, all elements have a "children" property which you can use to get a handle on an array of objects (or zero if the element has no children). Then you just iterate over the children and check their id property and compare it with the id you are looking for. But you can do much more than just checking the id. You have access to all of the properties. An easy way to check what is there is by printing a JSON representation of the element to the console. That should reveal to you what you can get.

    Here is a simple example:

    function showAllChildren(element){
        if(element && element.getChildren()){
            var children = element.getChildren();
            _.each(children, function(child){
                console.log(JSON.stringify(child));
            });
        }
    }
    

    You can call it like: showAllChildren($.form) - or whatever element you have that you want to test ;-)

    /John