ubuntu qml ListView模型重新加载U1Db查询

时间:2016-07-06 13:47:25

标签: listview model qml updates ubuntu-touch

我有一个ListView,他的模型来自U1db.Query从/到U1db的读取和保存操作有效,但我需要在数据库中插入新项目时更新ListView模型以显示插入的最后一个内容(即:我需要执行相同的查询)。我也尝试过ListView和UbuntuListView`,但我无法解决这个问题。当我拉动'刷新它的列表我得到错误:

Property 'update' of object U1db::Query(0xe097e0) is not a function

我看过sdk doc,但我找不到任何有用的例子。谢谢你的任何建议!

这里的片段(我省略了一些detils):

    import QtQuick 2.2
    import Ubuntu.Components 1.3
    import Ubuntu.Components.Popups 1.3

    import Ubuntu.Components.ListItems 1.3 as ListItem  //test

    import U1db 1.0 as U1db

//the delegate component used by the ListView
Component {
            id: peopleListDelegate

            Item {
                id: personItem                

                //draw a rectangle aroun the content to display 
                Rectangle {
                 //content omitted 
                }

                // This mouse region covers the entire delegate
                MouseArea {
                   //content omitted              
                }

                Row {
                    id: topLayout                    
                   //display some content to be shown inside the Rectangle
                 }
            }
        }


//the listView that show the DB Query result
        ListView  {

                         id: listView
                         anchors.fill: parent
                         model : allPeopleQuery
                         delegate: peopleListDelegate

                         highlight: highlightComponent                 
                         focus: true

                         Component{
                             id: listHeader

                             Item {
                                 width: parent.width
                                 height: units.gu(10)

                                 Text{
                                     anchors.bottom: parent.bottom
                                     anchors.horizontalCenter: parent.horizontalCenter
                                     text: i18n.tr("<b> Total people found: </b>") + listView.count
                                 }
                             }
                         }

                         header: listHeader

                         PullToRefresh  {                            
                                 refreshing: listView.model.status === ListModel.Loading
                                 onRefresh: listView.model.update()  // HERE THE PROBLEM, (also using reload() doesn't work)
                             }
                     }

        U1db.Database {
                id: mypeopleDb
               .....
            }

           U1db.Index{
               database: mypeopleDb
               id: all_field_index
               expression: .......
           }


          U1db.Query {
               id: allPeopleQuery
               index: all_field_index
               query: ["*", "*"]
           }

1 个答案:

答案 0 :(得分:0)

经过几天的尝试后,我发现了如何修复&#34;这个。 一个带有查询的ListView,U1db为&#34; model&#34;有一个内置的模型自动刷新(例如:如果您在数据库中添加/删除项目,并且查询的resultSet更改,模型将更新)。 但是,使用上面的代码在AdaptiveLayout内部进行切换 在具有如下声明的页面之间:

myAdaptiveLayout.addPageToNextColumn(aPage,Qt.resolvedUrl('AddPerson.qml'))

自动刷新模型不起作用!

如果您包含来自文件&#39; AddPerson.qml&#39;的页面代码在同一个qml文件里面定义了ListL模型自动刷新的AdaptiveLayout !!!

注意:我不知道此解决方案是解决方法还是qml错误。