Details
-
Suggestion
-
Resolution: Unresolved
-
P2: Important
-
6.2.2
Description
JavaScript arrays have a filter method that allows one to create a new list that includes selective elements from the source list.
It would be nice to have a filter method on the QML list type, which would do the same thing, only operating on QML lists instead of JavaScript arrays.
Suggested syntax would be exactly the same as the JavaScript Array.prototype.filter method.
An example that I was expecting to work is below and attached:
import QtQuick import QtQuick.Controls import QtQuick.Layouts ApplicationWindow { width: 640 height: 480 visible: true ColumnLayout { anchors.fill: parent Component.onCompleted: { var words = [ "Apple", "Pear", "Orange", "Banana", "Melon", "Dragonfruit" ]; function eFilterArray(currentElement) { return currentElement.includes("e"); } console.log("Array " + words + " length: " + words.filter(eFilterArray)); function eFilterText(currentElement) { return currentElement.text.includes("e"); } var eChildren = children.filter(eFilterText, 0); console.log("Number of fields that contain 'e' in their text: " + eChildren); } Text { text: "Apple" } Text { text: "Pear" } Text { text: "Orange" } Text { text: "Banana" } Text { text: "Melon" } Text { text: "Dragonfruit" } } }
Attachments
Issue Links
- clones
-
QTBUG-99041 Add 'reduce' method to QML list type
-
- Closed
-