当列表类型没有 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)
}
}
您定义了一个 JavaScript
list
,因此拼接应该可以工作:
arr.splice(1, 1)