简体   繁体   English

QML-形状类型,属性数据没有删除条目的方法?

[英]QML - Shape Type, Property data has no method for removing Entries?

For my application I am creating some dynamic lines to show them on screen. 对于我的应用程序,我正在创建一些动态行以在屏幕上显示它们。 I got tried creating the lines as in this example from the qt documentation: 我尝试根据qt文档中的示例创建线:

https://doc.qt.io/archives/qt-5.10/qtquick-shapes-content-interactive-qml.html https://doc.qt.io/archives/qt-5.10/qtquick-shapes-content-interactive-qml.html

In this example the shapepath is added into the data property of shape via: 在此示例中,shapepath通过以下方式添加到shape的data属性中:

shape.data.push(p); shape.data.push(p);

However I want to remove something from this list but neither pop() or splice work. 但是,我想从此列表中删除某些内容,但pop()或拼接工作均无效。 Is there a way to remove items from the data list property of Shape? 有没有一种方法可以从Shape的数据列表属性中删除项目?

In the qt doc, not even the push method was actually mentioned. 在qt doc中,实际上甚至没有提到push方法。

The data property in Shape is not a JS array and is quite limited. Shapedata属性不是JS数组,并且非常有限。

According to the documentation : 根据文档

Note that objects cannot be individually added to or removed from the list once created; 请注意,对象一旦创建就无法单独添加到列表或从列表中删除; to modify the contents of a list, it must be reassigned to a new list. 要修改列表的内容,必须将其重新分配给新列表。

So, you have to create a new list without the item you want to remove: 因此,您必须创建一个没有要删除的项目的新列表:

function removeFromShapeAt(index) {
            var d = []
            for (var i = 0; i !== shape.data.length; ++i) {
                if (i !== index) {
                    d.push(shape.data[i])
                }
            }
            shape.data = d
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM