Nested Contexts

Thread is closed for posting
3 posts, 0 answers
  1. Christopher
    Christopher avatar
    6 posts
    Member since:
    Mar 2011

    Posted 05 Mar 2015 Link to this post

    When using a control such as a ListView, the context changes to the individual item in the bound collection.  For example, see https://github.com/NativeScript/sample-Tasks/blob/master/Tasks/app/views/main.xml

    Is it possible to get the "parent" context if access to properties at that level are required to modify the display or style of the child controls?  

    Similarly, is it possible to get the index of the item in the collection that the ListView child is bound?  

    For example, these things could be used to create complex grid hierarchies (Tasks with subtasks), apply alternate row styling, etc.
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 06 Mar 2015 Link to this post

    Hi,

    You can catch itemLoading event to access ListView bindingContext. For example:

    XML
    <ListView itemLoading="listViewItemLoading" ...

    JavaScript
    function listViewItemLoading(args) {
        var listView= args.object;
        var listViewBindingContent = listView.bindingContext;
        var item = args.view;
        var itemBindingContext = args.view.bindingContext;
    }
    exports.listViewItemLoading = listViewItemLoading;

    Regards,
    Vlad
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Christopher
    Christopher avatar
    6 posts
    Member since:
    Mar 2011

    Posted 06 Mar 2015 Link to this post

    Interesting, thanks.  Was hoping for a method that would be usable from XML, similar to knockout's $root and $parent/$parents contexts. (http://knockoutjs.com/documentation/binding-context.html)
Back to Top