0

我需要在列表视图 blackberry 10 cascades 中获取行数qml吗?列表视图数据源模型类型为json. 我试过这个

ListItem.initialized ? ListItem.view.dataModel.childCount(ListItem.indexPath) : 0

但即使列表视图行数超过 1,它也只显示 0。

我的代码

dataModel: groupdatamodel 
listItemComponents: [ 
    ListItemComponent { 
        type: "header" 

        Container { 
            preferredWidth: 748 
            layout: DockLayout { }

            Label {
                text: "Title" 
                base: SystemDefaults.TextStyles.TitleText
                fontWeight: FontWeight.Bold
            }
        }

        Label { 
            id: subtitle 
            text: groupdatamodel.size() + "Items"

            textStyle { 
                base: SystemDefaults.TextStyles.SmallText 
                fontWeight: FontWeight.Bold
        } 
    }
]
4

5 回答 5

1
  1. 主.qml

    import bb.cascades 1.0
    import bb.data 1.0
    
    Page {
        content: Container {
            Label {
                text: "List View with json parsing"
            }
            ListView {
                id: listViewDemo
                dataModel: GroupDataModel {
                    grouping: ItemGrouping.None
                }
                listItemComponents: [
                    ListItemComponent {
                        type: "listItem"
                        StandardListItem {
                            title: ListItemData.ThumnailImage
                            description: ListItemData.CategoryID
                        }
                    }
                ]
                function itemType(data, indexPath) {
                    return "listItem";
                }
            }
        }
        attachedObjects: [
            DataSource {
                id: serviceDataSource
                source: "contacts.json"
                type: DataSourceType.Json
                onDataLoaded: {
                    listViewDemo.dataModel.clear();
                    listViewDemo.dataModel.insertList(data)
                }
            }
        ]
        onCreationCompleted: {
            serviceDataSource.load();
        }
    }
    
  2. 联系人.json

    [   {"CategoryID":"3","CategoryName":"News","CountryID":"1","Result":"OK"},
    

    {"CategoryID":"4","CategoryName":"Daily Paper","CountryID":"1","Result":"OK"},{"CategoryID":"5","CategoryName":"Thanthi","CountryID":"1","Result":"OK"}, {"CategoryID":"1","CategoryName":"Newspaper","CountryID":"1","Result":"OK"}, {"CategoryID":"2","CategoryName":"Magazine","CountryID":"1","Result":"OK"} ]

  3. 主文件

在主文件中添加以下行

#include <bb/data/DataSource>
#include <bb/data/JsonDataAccess>

Q_DECL_EXPORT int main(int argc, char **argv)
{
    // We want to use DataSource in QML
    bb::data::DataSource::registerQmlTypes();

4.文件名.PRO

LIBS += -lbbdata

于 2013-09-03T08:50:12.270 回答
0

you can use:

your_groupdatamodel.size().toString();

or

your_groupdatamodel.childCount(0);

in javascript code.

J.

于 2014-06-16T11:30:57.850 回答
0

我在我的项目中使用此代码,它工作正常:

 console.log("pcs count" + pcsListModel.childCount(0));
于 2013-01-16T08:45:10.973 回答
0

DataModel::childCount(ListItem indexPath) 返回由 indexPath 指定的列表中项目的子项计数,而不是数据模型中的数据项计数(因此可用于列表)。您需要询问实际的数据模型。例如 GroupDataModel::size() 返回 GroupDataModel 中的项目数,与 QListDataModel 类似。

于 2013-01-05T19:18:14.480 回答
0

除非您使用自定义数据模型,否则无法在标签中添加自定义元素。

于 2013-09-03T07:43:39.930 回答