如何从 QML 中的列表类型中删除项目

问题描述 投票:0回答:1

当列表类型没有 pop() 方法、remove() 方法或 splice() 方法时,如何从指定索引中删除元素。

import QtQuick 2.15
import QtQuick.Window 2.15

Window {
    width: 640
    height: 480
    visible: true
    property  list<QtObject> arr:[
        QtObject{
            property real a: 1.0
        },
        QtObject{
            property real a: 1.0
        },
        QtObject{

        },
        QtObject{

        }
    ]

    Component.onCompleted: {
        console.log(arr.length)
        arr.remove(1)//error:TypeError: Property 'remove' of object [object Object] is not a function
        console.log(arr.length)
    }
}
qt qml
1个回答
0
投票

您定义了一个 JavaScript

list
,因此拼接应该可以工作:

arr.splice(1, 1)
© www.soinside.com 2019 - 2024. All rights reserved.