JsonListModel QML Type

Import Statement: import .

Properties

Methods

Detailed Description

JsonListModel is a syncable list model. It could be used as a wrapper of other Javascript array object. Whatever the source is updated, it will trigger synchronization automatically. It will emit signals of insertion, removal and moving automatically.

Property Documentation

count : int

No. of items in this list model.


fields : array

Define the available fields of this model. If it is not assigned, JsonListModel will use the first appended record. Then you are not able to change afterward.

Example:

JsonListModel {
    keyField: "id"
    fields: [
        "id",
        "value"
    ]
}

keyField : string

Set the key field of data source. The value in key field should be unique.

If it is not set, JsonListModel won't be able to identify insertion, removal and moving changes.


source : array

JsonListModel is a wrapper of another Javascript array. Update this property will trigger the synchronization and emit changes according to the difference.

Example:

JsonListModel {
    keyField: "id"

    source: [
        { "id": "a", "value": 1},
        { "id": "b", "value": 2}
    ]

    fields: [
        "id",
        "value"
    ]
}

Method Documentation

void append(const QVariantMap & value)

Append an items at the end of list


QVariantMap get(int i) const

Returns the item at index in the list model.


int indexOf(QString field, QVariant value)

Get the index of the given record which is equal to input value on given field.

If it is not found, it will return -1.


void insert(int index, const QVariantMap & value)

Inserts an item at index position.


void move(int from, int to, int n)

Moves n items from one position to another.


void remove(int i, int count = 1)

Deletes the content at index from the model. You may specific the no. of items to be removed by count argument.


void set(int index, QVariantMap changes)

Changes the item at index in the list model with the values in changes. Properties not appearing in changes are left unchanged.

If index is equal to count() then a new item is appended to the list. Otherwise, index must be an element in the list.


void setProperty(int index, QString property, QVariant value)

Apply the changes to a record at index. Only modified value will be set.