Welcome!

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

Reply
Contributor
lvandyk
Posts: 19
Registered: ‎07-17-2012
My Device: BB 10 Alpha Device
My Carrier: Vodacom
Accepted Solution

DataSource data in JavaScript

[ Edited ]

I have the following in my QML:

 

        DataSource {
            id: dataSource
            source: "asset:///db.db"
            query: "select * from teams where id = 1"
            onDataLoaded: {
                
            }
        }

 

 In the onDataLoaded function, we have the 'data' variable. How can I extract the data from it and insert them into normal JS variables.

Please use plain text.
Developer
Zmey
Posts: 1,509
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: DataSource data in JavaScript

Hi,

 

For SQL queries, data is a list of maps. Sample code for iterating the list and accessing fields:

 

property string someProperty

[...]

onDataLoaded: { for (var i = 0; i < data.length; ++i) { var t = data[i] console.log("data[i]=" + t); // access fields as t.fieldname
// if (t.fieldname == ".....")
// someProperty = t.someOtherfield } }

 

 

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Contributor
lvandyk
Posts: 19
Registered: ‎07-17-2012
My Device: BB 10 Alpha Device
My Carrier: Vodacom

Re: DataSource data in JavaScript

Didn't realise it would be so easy! Thanks alot!
Please use plain text.