カスケードでカスタムListItemComponentを使用しようとしていますが、無視しています。ラベルを描画し、シアンに色付けしてListItemData.textを入力する代わりに、リストにListItemData.descriptionを入力します(私のjsonにはテキスト、説明、ステータス、画像があります)。ここでスクリーンショットを見ることができます。StandardListItemを使用すると、すべての情報が正しく表示されます。
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);
}
}