After watching many tutorials and trying out a lot of code snippets, i am still confused about when and how to use ObservableArray and binding. Trying to get a listview of values from my json array - alert shows them, console displays what i thought it would. the only thing not working is my listview. any assistance by anyone please! posted my javascript and corresponding xml below.
----updated my code. shows an array of six values with one of each in the itemTemplates. how to access every instance? and the keys? need to display key: value pairs and seemingly the keys are missing in the array. anything appreciated!
listview.js
testJsonArray = {
"results": [{
"testName": "Multiplizieren",
"testKlasse": 3,
"testFach": "Mathematik"
},
{
"testName": "Addieren",
"testKlasse": 3,
"testFach": "Mathematik"
}]
};
function onPageLoaded(args) {
var page = args.object;
var observableArray = require("data/observable-array");
var i = testJsonArray.results.length;
var tests = new observableArray.ObservableArray([]);
while (i--) {
t = testJsonArray.results[i];
tests.push([t.testName, t.testKlasse, t.testFach]);
};
var c = tests.length;
while (c--) {
console.log(c);
};
alert(tests);
page.bindingContext = {myItems: tests};
}
exports.onPageLoaded = onPageLoaded;
listview.xml
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="onPageLoaded">
<ScrollView>
<ListView id="listview" items="{{ myItems }}">
<ListView.itemTemplate>
<StackLayout orientation="horizontal">
<Label text="{{ $value }}" />
</StackLayout>
</ListView.itemTemplate>
</ListView>
</ScrollView>
</Page>