Edit list item in blackberry cascades QML

161 views Asked by At

I have successfully created a list view that populates a json file which I have created now I'm trying to edit the list view item. But I'm having trouble doing it, I keep getting error TypeError: Result of expression 'curData' [undefined] is not an object. Below is a sample code where I'm trying to edit the listview after the page is created.

This is the page where I load the list view

import bb.system 1.0
import bb.cascades 1.0
import bb.data 1.0
import Network.Communication 1.0
Page {
    Container {

        id: profilePage
        layout: DockLayout {
        }

        ListView {
            id: profileListView
            dataModel: contactsData
            listItemComponents: [
                ListItemComponent {
                    id: myItem
                    type: "item"
                    CustomListItemProfilePage {
                        id: listCell
                        background: Color.create(ListItemData.color)
                        text:  ListItemData.name 

                        onClicked: {
                    console.log(listCell.text);

                        }
                    }

                }



            ]

            onTriggered: {

            }

        }

    }
    onCreationCompleted:
    {
        var curData = contactsData.data([0,0])
        curData.name = curData.name + " : "+ _settings.getValueFor("loginUserName", "No login name");
        contactsData.updateItem([0,0],curData)
        console.log("on compleete LOADED:"+contactsData.data([0,0]).toString());
        profileDataSource.load();


    }
    attachedObjects: [

        GroupDataModel {
            id: contactsData
            sortingKeys: ["order"]
            grouping: ItemGrouping.None
        },
        DataSource {
            id: profileDataSource
            source: "asset:///Model/ProfileDetails.json"
            onDataLoaded: {
                contactsData.clear();
                contactsData.insertList(data);
            }
            onError: {
                console.log("JSON Load Error: [" + errorType + "]: " + errorMessage);
            }
        }


    ]


}

This is my sample json file. I'm trying to replace the text NAME with actual name that I get after login which is stored in _settings.getValueFor("loginUserName", "No login name")

[
{ "order": 1, "name": "NAME" ,"color":"#16A085" },
{ "order": 2, "name": "FIND FRIENDS" ,"color":"#2ECC71" },
{ "order": 3, "name": "INVITE" ,"color":"#3498DB" },
{ "order": 4, "name": "EDIT PROFILE" ,"color":"#34495E" }
]

This is the qml for my listview item

import bb.cascades 1.0
import QtQuick 1.0
import "Model/floatConstants.js" as Item

Container {
    property alias text: label.text
    property TextStyleDefinition textColor:label.textStyle
    signal clicked() 

    layout: DockLayout {
    }
    preferredHeight: Item.itemHeight
    preferredWidth: 1000.0
    Container {
        background: Color.Transparent
        horizontalAlignment: HorizontalAlignment.Center
        verticalAlignment: VerticalAlignment.Center
        Container {
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center

            Label {
                id: label
                text: "demo"
                textStyle {
                    base: textColor.style
                }

            }
            gestureHandlers: [
        TapHandler {
            onTapped: {
                clicked();
            }
        }
    ]
        }
    }

}

I'm new to blackberry and this is my first blackberry project. Please let me know if this is possible or if there is any other way to achieve this.

1

There are 1 answers

1
Bojan Kogoj On

Look at this:

var curData = contactsData.data([0,0])

At this point contactsData does not have data yet, you haven't loaded it yet. First call

profileDataSource.load();

I'm not sure why you would use ListView for such thing though.