I’ve got a JSON style array but I’m unable to access the individual elements. Any pointers what I’m doing wrong?
This was a test below:
<App>
<JavaScript>
var Observable = require("FuseJS/Observable");
var people = Observable(
{name: "Jake", surname: "Thomas"},
{name: "Julie", surname: "Jones"},
{name: "Jim", surname: "Smith"}
);
people.add({name: "Hana", surname: "Honey"});
people.add({name: "Darren", surname: "Hopkirk"});
console.log(people[1].surname.value);
module.exports = {
people: people
}
</JavaScript>
<StackPanel>
<Each Items="{people}">
<Text Value="{name}" /><Text Value="{surname}" />
</Each>
</StackPanel>
</App>
The console.log statement produces an error: Cannot read property 'surname' of undefined
I’ve also tried using people.indexOf(“Smith”) to find a particular item in array, and then deal with it, but I don’t seem to be able to get a result. indexOf just returns -1. indexOf works fine if I just use a straight array like this var colors = Observable(“Red”, “Green”, “Blue”); so I’m assuming it doesn’t work with nested structure?
Thanks in advance
Mark.