<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 的子节点

      Delete children of QML Grid(删除 QML Grid 的子节点)
      <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 的子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                quot;Status Code:200 OK (from ServiceWorker)quot; in Chrome Network DevTools?(“状态码:200 OK(来自 ServiceWorker)在 Chrome 网络开发工具中?)
                How to set a header for a HTTP GET request, and trigger file download?(如何为 HTTP GET 请求设置标头并触发文件下载?)
                Adding custom HTTP headers using JavaScript(使用 JavaScript 添加自定义 HTTP 标头)
                SQL Query DocumentDB in Azure Functions by an integer not working(通过整数在 Azure Functions 中 SQL 查询 DocumentDB 不起作用)
                Azure Functions [JavaScript / Node.js] - HTTP call, good practices(Azure Functions [JavaScript/Node.js] - HTTP 调用,良好实践)
                Azure Functions - Import Custom Node Module(Azure Functions - 导入自定义节点模块)

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

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

                        • <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>

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