【问题标题】:How to load source data in GroupDataModel for ListView in Blackberry 10 cascade?如何在 Blackberry 10 级联中为 ListView 加载 GroupDataModel 中的源数据?
【发布时间】:2013-08-26 08:50:13
【问题描述】:

这是我想从位于我的设备共享文件夹中的 xml 文件中加载 source: 数据的代码行。

那个xml文件的路径是QFile textfile("/accounts/1000/shared/documents/myData.xml");

我的代码是:

import bb.cascades 1.0
import bb.data 1.0
Page {
content: ListView {
id: listView
dataModel: dataModel
    ...
}
attachedObjects: [
    GroupDataModel {
    id: dataModel
    },
        DataSource {
      id: dataSource


     //---------------------------------------
     //Here I want to load xml file
     //---------------------------------------
      source: "/accounts/1000/shared/documents/myData.xml"
    //---------------------------------------


      query: "/contacts/contact"
      onDataLoaded: {
        dataModel.insertList(data);
      }
    }
  ]
  onCreationCompleted: { dataSource.load(); }
}

任何人请帮助我,如何在位于上述设备目录位置的 GroupDataModel 中加载 xml 文件。

提前致谢。

【问题讨论】:

    标签: xml listview blackberry-10 blackberry-cascades datamodel


    【解决方案1】:

    我们有两个部分可以做到这一点:

    第一个允许您的应用程序使用共享文件夹

    步骤:

    1. 转到项目中的 bar-descriptor.xml
    2. 选择应用程序
    3. 在共享文件中检查 true

    第二个是使用C++获取正确的路径,并在上下文属性中发送给Qml

    这在您的 ApllicationUI.cpp 中 C++ 代码

    // Build the path, add it as a context property, and expose
    // it to QML
    QString workingDir = QDir::currentPath();
    QString path = "file://" + workingDir +"/shared/documents/model.xml";
    QDeclarativePropertyMap* dirPaths = new QDeclarativePropertyMap;
    dirPaths->insert("documents", QVariant(QString(path)));
    qml->setContextProperty("dirPaths", dirPaths);
    

    QML

        dataModel: XmlDataModel {
                source: dirPaths.documents
        } 
    

    【讨论】:

      【解决方案2】:

      此快照描述了如何访问权限->共享文件

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多