Last active
December 11, 2015 01:49
-
-
Save stevenbeeckman/4526166 to your computer and use it in GitHub Desktop.
An example of how to call a JSON webservice directly from BlackBerry 10 Cascades QML. This gist also shows how to convert Date strings purely in QML. This gist is part of this blogpost: http://www.shadowmedia.be/bbdevbe/2013/01/13/listing-json-data-from-a-webservice-using-pure-qml/.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bb.cascades 1.0 | |
import bb.data 1.0 // don't forget to add "LIBS += -lbbdata" to your .pro file! | |
Page { | |
id: pgDetail | |
actions: [ | |
ActionItem { | |
title: qsTr("Refresh") | |
onTriggered: { | |
dataSource.load() | |
} | |
} | |
] | |
paneProperties: NavigationPaneProperties { | |
backButton: ActionItem { | |
onTriggered: { | |
navigationPane.pop() | |
} | |
} | |
} | |
Container { | |
ListView { | |
dataModel: dataModel | |
listItemComponents: [ | |
ListItemComponent { | |
type: "item" | |
StandardListItem { | |
title: convertDate(ListItemData.someDateField) // call a function | |
description: ListItemData.someField | |
imageSpaceReserved: false | |
function convertDate(toBeConvertedDate) { | |
console.debug("registration date: " + toBeConvertedDate); | |
console.debug("type of registration date: " + typeof toBeConvertedDate); | |
var workingDate = new Date(); | |
workingDate.setFullYear(toBeConvertedDate.substring(0,4)); | |
console.debug("year: " + toBeConvertedDate.substring(0,4)); | |
workingDate.setMonth(toBeConvertedDate.substring(5,7) - 1); | |
console.debug("month: " + toBeConvertedDate.substring(5,7)); | |
workingDate.setDate(toBeConvertedDate.substring(8,10)); | |
console.debug("date: " + toBeConvertedDate.substring(8,10)); | |
workingDate.setHours(toBeConvertedDate.substring(11, 13)); | |
console.debug("hours: " + toBeConvertedDate.substring(11, 13)); | |
workingDate.setMinutes(toBeConvertedDate.substring(14,16)); | |
console.debug("minutes: " + toBeConvertedDate.substring(14,16)); | |
workingDate.setSeconds(toBeConvertedDate.substring(17,19)); | |
console.debug("seconds: " + toBeConvertedDate.substring(17,19)); | |
//var toBeReturnedDate = Qt.formatDateTime(workingDate, "yyyy/MM/dd HH:mm:ss"); | |
var toBeReturnedDate = Qt.formatDateTime(workingDate, "ddd dd MMM yyyy"); | |
console.debug("toBeReturnedDate: " + toBeReturnedDate); | |
return toBeReturnedDate; | |
} | |
} | |
} | |
] | |
} | |
} | |
attachedObjects: [ | |
GroupDataModel { | |
id: dataModel | |
sortingKeys: ["someImportantFieldName"] | |
sortedAscending: false | |
grouping: ItemGrouping.None | |
}, | |
DataSource { | |
id: dataSource | |
source: "http://some.url.that.returns.json" | |
type: DataSourceType.Json | |
onDataLoaded: { | |
dataModel.clear() | |
dataModel.insertList(data) | |
} | |
} | |
] | |
onCreationCompleted: { | |
dataSource.load() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment