I'm trying to use a custom ListItemComponent in my cascades however it is ignoring it. Instead of drawing my Label, coloring it cyan and putting ListItemData.text in, it fills my list with ListItemData.description (my json has text, description, status and image). You can see screenshot here. If i use StandardListItem all information is displayed properly.
QML:
Page {
Container {
ListView {
id: myListView
dataModel: MyListModel {
id: myListModel
}
listItemComponents: [
ListItemComponent {
type: "listItem"
Container {
id:item
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
Label {
id: text
text: ListItemData.text
textStyle {
color: Color.Cyan
}
}
}
}
]
}
}
onCreationCompleted: {
myListModel.load("app/native/assets/mydata.json")
}
}
c++:
void MyListModel::load(const QString& file_name)
{
bb::data::JsonDataAccess jda;
QVariantList lst = jda.load(file_name).value<QVariantList>();
if (jda.hasError()) {
bb::data::DataAccessError error = jda.error();
qDebug() << file_name << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
}
else {
qDebug() << file_name << "JSON data loaded OK!";
append(lst);
}
}
QVariant MyListModel::value(int ix, const QString &fld_name)
{
QVariant ret;
if(ix >= 0 && ix < size()) {
QVariantMap curr_val = QVariantListDataModel::value(ix).toMap();
ret = curr_val.value(fld_name);
}
return ret;
}
void MyListModel::setValue(int ix, const QString& fld_name, const QVariant& val)
{
if(ix >= 0 && ix < size()) {
QVariantMap curr_val = QVariantListDataModel::value(ix).value<QVariantMap>();
curr_val[fld_name] = val;
replace(ix, curr_val);
}
}