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!
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!
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.
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.