I having been using fetch to get data from a server but it has been working because the data return is having is a numeric array and not an array of a numeric array:
This Sample data return works perfectly when I use Each to display:
{ "responseData":
[
{
"author": "Hermione Robinson"
},
{
"author": "Herman Johnson"
}
]
}
This Sample data return doesn’t when I use :
{
[
{
"author": "Hermione Robinson"
},
{
"author": "Herman Johnson"
}
]
}
But the API am using returns data in the second format. I did a hack (var obj = { “model”: responseObject } for it to work. See the code below.
var Observable = require("FuseJS/Observable");
var data = Observable();
fetch(url)
.then(function(response) { return response.json(); })
.then(function(responseObject) {
var obj = { "model": responseObject };
data.value = obj;
});
module.exports = {
data: data,
};
My question:
What is the right way to implement the above fetch code without using the hack var obj = { “model”: responseObject }; ? I would love to use the data exactly the way it is return. When it is return this way the Observable doesn’t work.