I am trying to make a request to the NodeJS API. For the client, I use the Mithril framework. I used my first example to query and retrieve data:
var Model = {
getAll: function() {
return m.request({method: "GET", url: "http://localhost:3000/store/all"});
}
};
var Component = {
controller: function() {
var stores = Model.getAll();
alert(stores);
alert(stores());
},
view: function(controller) {
...
}
};
After doing this, I noticed that in Chrome Developer Tools, the API responds correctly as follows:
[{"name":"Mike"},{"name":"Zeza"}]
I can not find a way to get this data in the controller. They mentioned that using this method, var can hold undefineduntil the request is complete, so I followed the following example, adding:
var stores = m.prop([]);
Before the model and change the request to:
return m.request({method: "GET", url: "http://localhost:3000/store/all"}).then(stores);
I could do something wrong because I get the same result.
The goal is to get the data from the response and send it to the view for repetition.