Access listView model inside another model

Diego Desenvolvedor

I've the following scenario:

ListModel {
    id: myModel
}

ListView {
    id: listView
    anchors.fill: parent
    model: myModel
    delegate: recipeDelegate
}    

Component {
    id: recipeDelegate

    Item {
        ...
        ...

        property var modelTag: row.model

        ListView
        {
            id: row
            delegate: recipeDelegateTags                   
            width: parent.width
            height: contentItem.height

            model: ListModel {
                id: myModel2
               }
         }
 }

Component { // I need to access this 

    id: recipeDelegateTags

    Item {
        id: recipeTags 
        width: parent.width
        height: 35

        Text {
            id: ic
            font.family: fontAwesome.name
            color: cor
            font.pixelSize: 16
            text: checked_ ? "\uf046" : "\uf096"
            width: 15

            anchors.left: parent.left
            anchors.leftMargin: 50
            anchors.verticalCenter: parent.verticalCenter
        }

        MediumText
        {
            anchors.verticalCenter: ic.verticalCenter
            text: titulo
            color: cor
            font.family: localFont.name
            anchors.left: ic.right
            anchors.leftMargin: 10
        }
    }
}

I'm able to append data in myModel with a js function like this:

function appendItem(a, b)
{
    myModel.append({"titulo": a, "id": b})
}

The question: how I access myModel2 to append some data?

I've already tried the following, without success:

function adicionaTag(a, b, c, d)
{
    for(var i = 0; i < myModel.count; i++) {
      var elemCur = myModel.get(i);
      if(a === elemCur.id) {
         console.log("property", elemCur.modelTag);
      }
   }
}

Can you guys help me? Thanks!

Diego Desenvolvedor

THE SOLUTION:

The resolution was based on @Maciek comment and @derM explanation. As I was using QJsonArray, I thought I could just loop and then access the myModel2 child component. Well, it's not that easy like that, as explained in the comments, the component can not be easily accessed. I have tried in many ways, both by loop in QML and in c ++ using findChild <>. In the end, it was much easier to just loop in QJSonArray and put it all together in a string, pass as an argument in myModel.append and then use the js split function:

Component {
   id: recipeDelegate

   Item {
    ...
    ...

       TagComponnent
       {
        id: row
        myString: someData               
      }
    }
 }

Inside TagComponent:

Item {    
    property string myString
    property variant stringList

     onMyStringChanged:
     {
        stringList = myString.split(';')
        var arrayLength = stringList.length

        for (var i = 0; i < arrayLength; i++) {
           appendItem(stringList[i], stringList[i+1])
           i++
    }
     }


     function adicionaTag(a, b)
     {
        myModel.append({"titulo": a, "cor": b})
     }        

     ListModel {
       id: myModel
     }

    ListView {
       ...
       model: myModel
       delegate: recipeDelegateTags
  }

 Component {
    id: recipeDelegateTags

       Item {
           ...
           ...

           MediumText
          {
              text: titulo
              color: cor
          }
      }
  }
}

To append:

function appendItem(a)
{
  myModel.append("myString": someData)
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

NoMethodError when attempting to access attribute of another model

From Dev

CakePHP: How to access $this->request inside a model

From Dev

Access to model data from listview item template on Kendo

From Dev

Ruby on rails - access model data within another model

From Dev

Ember access model inside a controller

From Dev

How do you access the id of a Django model inside the model object?

From Dev

Update model from inside of another controller

From Dev

How can I access the value of ForeignKey inside the model definions?

From Dev

Access model attributes inside DisplayTemplate

From Dev

Ruby on rails. Create 'model' from inside another controller

From Dev

Access a variable defined inside a model's method in a controller.

From Dev

LoopBack access another model

From Dev

Model collection inside a Model

From Dev

Binding model inside model in angularjs

From Dev

can't access addActionListener method inside the createCell method in the table model

From Dev

Backbone insert data inside Model from another

From Dev

Access a model method from another model in Cake

From Dev

AngularJS - access model from another directive

From Dev

MvvmCross - manually add View to Linear Layout - access model inside event

From Dev

How to access access of another model relationship from a model relationship in nodejs mongoose

From Dev

update a model in a ng-repeat inside another

From Dev

LoopBack access another model

From Dev

Model collection inside a Model

From Dev

Binding model inside model in angularjs

From Dev

How to access in controller an angular model inside another model?

From Dev

Access ListView model within the Repeater component in the delegate

From Dev

WPF MVVM: Access a listview object from View Model

From Dev

django ListView - custom queryset by joinining with another model

From Dev

Django - Access specific field from a model to another

Related Related

  1. 1

    NoMethodError when attempting to access attribute of another model

  2. 2

    CakePHP: How to access $this->request inside a model

  3. 3

    Access to model data from listview item template on Kendo

  4. 4

    Ruby on rails - access model data within another model

  5. 5

    Ember access model inside a controller

  6. 6

    How do you access the id of a Django model inside the model object?

  7. 7

    Update model from inside of another controller

  8. 8

    How can I access the value of ForeignKey inside the model definions?

  9. 9

    Access model attributes inside DisplayTemplate

  10. 10

    Ruby on rails. Create 'model' from inside another controller

  11. 11

    Access a variable defined inside a model's method in a controller.

  12. 12

    LoopBack access another model

  13. 13

    Model collection inside a Model

  14. 14

    Binding model inside model in angularjs

  15. 15

    can't access addActionListener method inside the createCell method in the table model

  16. 16

    Backbone insert data inside Model from another

  17. 17

    Access a model method from another model in Cake

  18. 18

    AngularJS - access model from another directive

  19. 19

    MvvmCross - manually add View to Linear Layout - access model inside event

  20. 20

    How to access access of another model relationship from a model relationship in nodejs mongoose

  21. 21

    update a model in a ng-repeat inside another

  22. 22

    LoopBack access another model

  23. 23

    Model collection inside a Model

  24. 24

    Binding model inside model in angularjs

  25. 25

    How to access in controller an angular model inside another model?

  26. 26

    Access ListView model within the Repeater component in the delegate

  27. 27

    WPF MVVM: Access a listview object from View Model

  28. 28

    django ListView - custom queryset by joinining with another model

  29. 29

    Django - Access specific field from a model to another

HotTag

Archive