Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 54
Registered: ‎05-23-2012
My Device: Developer
My Carrier: Developer

Organising QML

I have this same block of QML (inside the onTriggered) in several places:


List View {
onTriggered: {
// START BLOCK var chosenItem = <Some DataModel>.data(indexPath); var contentpage = detailsPageDefinition.createObject(); contentpage.titleName = chosenItem.ContentName ... Set a whole bunch of other property aliases, always the same. ... contentpage.initDetailsPage(chosenItem.ContentType, chosenItem.ContentId); // Push the content page to the navigation stack. <Some NavigationPane>.push(contentpage);
// END BLOCK } }

Obviously it's poor style to have this big chunk copied and pasted a bunch of times throghout my QML. How can I have this in a separate file and included where I need it? The only things that change are the parts in < >.



I know exactly where the problem *might* be.
Posts: 181
Registered: ‎07-19-2012
My Device: Q5, Q10, Z10, Z30, PlayBook
My Carrier: Carrier

Re: Organising QML

[ Edited ]

There are probably some JavaScript external function approaches you can do (I am not familiar with them) but one way I have done it is created a function in my root element (TabbedPane), gave it id: root and then anywhere in QML where QML is in the tree of that root I just call root.myFunction to call this function. Hope this helps. 


PS: the only problem with this approach is that if the common function uses local elements / properties which may not be directly referencable from the root you need to pass them in the function parameters. This is probably best approach for more static, calculation type functions.

If you find my post helpful please "like" it and "accept as a solution"
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Organising QML



This document describes how to import external Javascript files in QML. I think this should work with Cascades too:



Andrey Fidrya, @zmeyc on twitter
Posts: 71
Registered: ‎09-19-2012
My Device: Z10 very soon
My Carrier: Play

Re: Organising QML