I am requesting JSON data and can display it in the console no problem.
app.request.json(‘http://localhost:3000/allevents’, function (mydata) {
app.data.raise = mydata;
console.log(mydata);
});
I then want to use it under the name ‘raise’ throughout my app and have assigned it to app.data.raise.
However when I print app.data to the console I can see ‘raise’ but when I print app.data.raise to the console I get undefined.
app.request.json is async function, when you calling console.log(app.data.raise) on end script request has not yet completed and the data has not been received. It is necessary to call functions after the completion of the request
app.request.json('http://localhost:3000/allevents', function (mydata) {
app.data.raise = mydata;
console.log(mydata);
jsonParse(mydata);
});
function jsonParse(data){
console.log(app.data.raise);
}
or
app.request.json('http://localhost:3000/allevents', jsonParse);
function jsonParse(data){
app.data.raise = data
console.log(app.data.raise);
}
I see what you are saying. Do you know how I can place my request.json within the Framework7 app main instance and assign it to raise so I can then use $root.raise on a template with handles for {{city}}, {{venue}} etc.
Something like this but currently I receive cannot set property ‘raise’ of undefined: