<small id='ZydL2'></small><noframes id='ZydL2'>

      <legend id='ZydL2'><style id='ZydL2'><dir id='ZydL2'><q id='ZydL2'></q></dir></style></legend>
      • <bdo id='ZydL2'></bdo><ul id='ZydL2'></ul>

    1. <tfoot id='ZydL2'></tfoot>
    2. <i id='ZydL2'><tr id='ZydL2'><dt id='ZydL2'><q id='ZydL2'><span id='ZydL2'><b id='ZydL2'><form id='ZydL2'><ins id='ZydL2'></ins><ul id='ZydL2'></ul><sub id='ZydL2'></sub></form><legend id='ZydL2'></legend><bdo id='ZydL2'><pre id='ZydL2'><center id='ZydL2'></center></pre></bdo></b><th id='ZydL2'></th></span></q></dt></tr></i><div id='ZydL2'><tfoot id='ZydL2'></tfoot><dl id='ZydL2'><fieldset id='ZydL2'></fieldset></dl></div>
    3. 删除 QML Grid 的子节点

      时间:2023-08-01
      <tfoot id='13Hue'></tfoot>

        <tbody id='13Hue'></tbody>

            <i id='13Hue'><tr id='13Hue'><dt id='13Hue'><q id='13Hue'><span id='13Hue'><b id='13Hue'><form id='13Hue'><ins id='13Hue'></ins><ul id='13Hue'></ul><sub id='13Hue'></sub></form><legend id='13Hue'></legend><bdo id='13Hue'><pre id='13Hue'><center id='13Hue'></center></pre></bdo></b><th id='13Hue'></th></span></q></dt></tr></i><div id='13Hue'><tfoot id='13Hue'></tfoot><dl id='13Hue'><fieldset id='13Hue'></fieldset></dl></div>

            <small id='13Hue'></small><noframes id='13Hue'>

            <legend id='13Hue'><style id='13Hue'><dir id='13Hue'><q id='13Hue'></q></dir></style></legend>
              • <bdo id='13Hue'></bdo><ul id='13Hue'></ul>
              • 本文介绍了删除 QML Grid 的子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想遍历 QML Grid 的子节点并使用 Javascript 销毁每个子节点.

                I want to loop through a QML Grid's children and destroy each of them using Javascript.

                Grid {
                  id: contentGrid
                  spacing: 10
                
                  ImageItem { imageSource: "file:/foo.jpeg"  } // destroy this
                  ImageItem { imageSource: "file:/bar.jpeg"  } // destroy this as well
                }
                

                我试图做这样的事情,但到目前为止它不起作用.

                I tried to do something like this but it's not working so far.

                for(var i = 0; contentGrid.children.length() < i; i++) {
                    contentGrid.childAt(i).destroy();
                }
                

                推荐答案

                您在上面的尝试中遇到了许多问题...首先,您需要向后迭代,因为您将移动孩子的内容随着您前进(即,如果您删除#1,编号#2 将成为孩子#1,然后您将去删除#2,这将是旧的孩子#3).

                You have a number of problems in your attempt above... First, you'll need to iterate backwards because you'd be shifting the contents of the children down as you advance (ie, if you delete #1, number #2 would become child #1 and then you'd go to delete #2 which would be the old child #3).

                其次,您需要以不同的方式访问孩子.childAt() 函数用于在屏幕上的特定 x,y 处定位孩子,而不是列表中的位置.

                Second, you need to access the children differently. The childAt() function is for locating a child at a particular x,y on the screen, not a position in a list.

                试试这个:

                import QtQuick 1.0
                
                Rectangle {
                  width: 400
                  height: 400
                  Grid {
                    id: contentGrid
                    spacing: 10
                
                    Text { text: "foo"  } // destroy this
                    Text { text: "bar"  } // destroy this as well
                  }
                  MouseArea {
                    anchors.fill: parent
                    onClicked: {
                      for(var i = contentGrid.children.length; i > 0 ; i--) {
                        console.log("destroying: " + i)
                        contentGrid.children[i-1].destroy()
                      }
                    }
                  }
                }
                

                这篇关于删除 QML Grid 的子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:嵌套 CSS 网格是不好的做法吗? 下一篇:jQuery 图像网格系统

                相关文章

                  <tfoot id='eCb9a'></tfoot>
                    <bdo id='eCb9a'></bdo><ul id='eCb9a'></ul>

                  1. <small id='eCb9a'></small><noframes id='eCb9a'>

                  2. <i id='eCb9a'><tr id='eCb9a'><dt id='eCb9a'><q id='eCb9a'><span id='eCb9a'><b id='eCb9a'><form id='eCb9a'><ins id='eCb9a'></ins><ul id='eCb9a'></ul><sub id='eCb9a'></sub></form><legend id='eCb9a'></legend><bdo id='eCb9a'><pre id='eCb9a'><center id='eCb9a'></center></pre></bdo></b><th id='eCb9a'></th></span></q></dt></tr></i><div id='eCb9a'><tfoot id='eCb9a'></tfoot><dl id='eCb9a'><fieldset id='eCb9a'></fieldset></dl></div>

                    <legend id='eCb9a'><style id='eCb9a'><dir id='eCb9a'><q id='eCb9a'></q></dir></style></legend>