This is a migrated thread and some comments may be shown as answers.

Nested Contexts

2 Answers 119 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Christopher
Top achievements
Rank 1
Christopher asked on 05 Mar 2015, 07:41 PM
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 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 06 Mar 2015, 07:24 AM
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.

 
0
Christopher
Top achievements
Rank 1
answered on 06 Mar 2015, 03:22 PM
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)
Tags
General Discussions
Asked by
Christopher
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Christopher
Top achievements
Rank 1
Share this question
or