2

Hello I have a simmiliar question as this one: BlackBerry 10 Cascades: How do I load data into a DropDown? The only thing i want to know is how to do this with a ListView instead of a dropdown?

Thanks in advance!

Community
  • 1
  • 1
basnijkamp
  • 152
  • 3
  • 15

2 Answers2

0

The ListView displays data from a DataModel which is an abstract data type. Which specific type of data model you use depends on the source of your data. You place your data in the appropriate data model then assign the data model to the ListView.

Richard
  • 8,920
  • 2
  • 18
  • 24
  • Thanks for the reply, In my case I want to parse a json from the internet to the ListView. Can you give me a code example? Kind regards Bas – basnijkamp Apr 21 '13 at 09:21
  • There is a Jason sample application in the sample app collection: https://developer.blackberry.com/cascades/sampleapps/ – Richard Apr 21 '13 at 18:50
0

To load data into a dropdown, instead of a listview, use this code:

DropDown {
    id: dropdown
    attachedObjects: [
        ComponentDefinition {
            id: compDefDD
            Option {
                description: "your default value for each Option"
            }
        },
        DataSource {
            id: dropDownDataSource
            // Load the data from an SQL database, based on a specific query
            source: "asset:///database.sql
            query: "select * from <yourtable>"
            onDataLoaded: {
                //the method is the code above
                for (var i = 0; i < data.length; i ++) {
                    var option = compDefDD.createObject();
                    option.text = data[i].SQLcolumn1;
                    option.value = data[i].SQLcolumn2;
                    dropdown.add(option);
                }
            }
            onError: {
                console.debug(errorMessage + " : " + errorType);
            }
        }
    ]
    onCreationCompleted: {
        dropDownDataSource.load();
    }
}

In this example I load data from a sql database. If you use another source of the data see page reference for more details.