2016-07-06 92 views
0

我有一個ListView與他的模型來自U1db.Query讀取和保存操作從/到U1db的作品,但我需要更新ListView模型時,插入一個新的項目數據庫來顯示插入的最後內容(即:我需要執行相同的查詢)。我也試過用ListView和UbuntuListView`,但我無法解決這個問題。當我「拉」列表刷新它,我得到的錯誤:ubuntu qml ListView模型重新加載U1Db查詢

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

我已經看了看SDK文檔,但我還沒有發現任何有用的例子。感謝您的任何建議!

這裏摘錄(我省略了一些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: ["*", "*"] 
      } 

回答

0

嘗試一些天后我已經找到了如何「修理」這一點。 將查詢與U1db查詢作爲「模型」的ListView具有模型的內置自動刷新(例如:如果在數據庫中添加/刪除項目並且查詢的結果集更改模型將被更新)。 但是,使用上面的代碼的AdaptiveLayout內,並與聲明切換頁面之間 像:

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

模型的自動刷新不起作用!

如果在定義了AdaptiveLayout的同一個qml文件中包含來自文件'AddPerson.qml'的頁面代碼,那麼ListView模型自動刷新將起作用!

注意:我不知道此解決方案是解決方法還是qml錯誤。