I had two pages. Concerts and Timetable of Concerts.
At first time all show correct. I can go to timetable and back with both concerts. But if i want after second concert go to the first each items not shows.
my code is:
Thanks for any help
I had two pages. Concerts and Timetable of Concerts.
At first time all show correct. I can go to timetable and back with both concerts. But if i want after second concert go to the first each items not shows.
my code is:
My problem was that i had function in Context.js file called:
`
let storedFileData = JSON.parse(FileSystem.readTextFromFileSync(FileSystem.dataDirectory + “/” + “nebdata.json”));
let concerts = [];
Object.keys(storedFileData.maps).forEach(function(key) {
let concert = storedFileData.maps[key];
let concertPerformances = [];
if(concert.performances[0]){
concert.performances.forEach(function(item){
performances[item].textDate = unixConverter(performances[item].date, “dateMonth”);
performances[item].textDay = unixConverter(performances[item].date, “day”);
if(!performances[item].place){
performances[item].place = “Место проведения не определено”;
}
concertPerformances.push(performances[item]);
});
}
concert.performances = concertPerformances;
concerts.push(concert);
});
function getConcert(id) {
let concert = concerts.find(function(item) {
return item.id == id;
});
if(concerts.events[0]){
concerts.events = concerts.events.map(function(item){
return events[item];
});
}When I go second time to this function with the same id i had empty block. Problem was, that when I manipulate with concert, I don
t know why, but I overrided variable concerts.
Solution: i rewrite this function and added function clone(obj) { return JSON.parse(JSON.stringify(obj)); }; let clonedConcert = clone(concert);
And now my function look:
`function getConcert(id) {
let concert = concerts.find(function(item) {
return item.id == id;
});
let clonedConcert = clone(concert);
if(clonedConcert.events[0]){
clonedConcert.events = clonedConcert.events.map(function(item){
return events[item];
});
}`
and now everything works fine.
I will be apritiate if somebody tell me why variable concerts was overrided.