0
我已經成功創建了一個列表視圖,填充我現在創建的json文件,現在我試圖編輯列表視圖項目。但我遇到了麻煩,我不斷收到錯誤TypeError:表達式'curData'[undefined]的結果不是對象。下面是一個示例代碼,我試圖在創建頁面後編輯列表視圖。編輯黑莓瀑布列表項QML
這是我加載列表視圖頁面
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);
}
}
]
}
這是我的樣本JSON文件。我想,以取代與實際名稱的文本名稱我存儲在_settings.getValueFor登錄後獲得(「loginUserName」,「無登錄名」)
[
{ "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" }
]
這是我的ListView項的QML
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();
}
}
]
}
}
}
我是黑莓新手,這是我的第一個黑莓項目。請讓我知道這是否可能,或者是否有其他方法可以實現。
我試圖在加載profileDataSource.load()後設置curData,但它仍然顯示相同的錯誤。你建議Bojan有什麼其他方法? – Gamerlegend 2014-11-23 05:25:52