我試圖使用自定義ListItemComponent在我的級聯但它是忽略它。除了繪製我標籤,着色它青色並把ListItemData.text中,它填補了我的名單與ListItemData.description(我的JSON有文字,描述,狀態和圖像)。 You can see screenshot here。如果我使用StandardListItem正確顯示的所有信息。的ListView不使用自定義ListItemComponent
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);
}
}
有人可以添加「ListItemComponent」標籤請,我沒有足夠的代表。 – 2013-03-08 18:06:39