Hi, I have this code
https://snippet.webix.com/0f89nuut
my problem is I need to load data from a POST call, but the data is not showing in the map, also I get this error:
TypeError: Cannot read property ‘each’ of undefined
Hey @Hellekin, in this case your variable clients
is returning a promise, which you have to wait for to resolve, and only then will you be able to parse the data coming from the response. The correct form would look something like this:
var clients = webix.ajax().post("//localhost:3000/webapi/clientes", { codemp: state }, "json");
clients.then((data) => { //wait for the promise to resolve
view.parse(data.json()) //data.json() will return the data in the JSON format
})
view
in this case will be the Open Maps widget.
As for the
TypeError: Cannot read property ‘each’ of undefined
this is referring to the line 43 in the snippet:
clients.data.each(item => {
Where clients
is a promise in this case and doesn’t have a method each
.
Hi, @Dzmitry I trying to use this code:
var clients = webix.ajax().post("//localhost:3000/webapi/clientes", { codemp: state }, “json”);
clients.then((data) => {
console.log(data.json().length);
console.log(data.json().nomcli[1]);
this.$$("map").getMap(true).then(function (map) {
data.each(item => {
var marker = L.marker([item.latcli, item.loncli]);
marker.bindPopup(item.nomusu).openPopup();
marker.addTo(map);
});
});
});
but the data is not showing in the map, please help
try to change data.each
to data.json().forEach
clients.then((data) => {
console.log(data.json().length);
console.log(data.json().nomcli[1]);
this.$$("map").getMap(true).then(function (map) {
data.json().forEach(item => {
var marker = L.marker([item.latcli, item.loncli]);
marker.bindPopup(item.nomusu).openPopup();
marker.addTo(map);
});
});
});