Problem with data in webix jet

Hi, I want to use my data from server but I don't know how to call json data from "sellers" I tried var data=sellers and it didn't work, this is my code:

import { JetView } from "webix-jet";
import { sellers } from "models/records";

export default class SellerView extends JetView {
config() {
return {
rows: [
{
cols:
[
{
collapsed: false,
header: "Localizacion",
body: {
view: "unitlist", width: 250,
id: "sellersUnitList", select: true,
template: "

#id#. #nomusu#

",
width: 200,
uniteBy: function (obj) {
return obj.codsup;
},
},
},
{
template: "maps",
view: "open-map",
id: "map",
zoom: 19,
center: [-1.268335, -78.622616],
},
],
},
],
};
}
init() {
this.$$("sellersUnitList").parse(sellers);
var data = sellers;
console.log(data);
$$("map").getMap(true).then(function (map) {
for (i = 0; i < data.length; i++) {
var marker = L.marker([data[i].latitud, data[i].longitud]);
marker.bindPopup(data[i].nomusu).openPopup();
marker.addTo(map);
}
});
}
}

please help

Comments

  • it depends on your sellers structure.
    can you share it?

  • I have a records.js file an the code is:

    export const sellers = new webix.DataCollection({ url:"/server/business_employees" });

    and my server file code is:

    const express = require("express");
    const session = require("express-session")
    const bodyParser = require("body-parser");

    const app = express();
    app.use(express.static("public"));
    app.use(bodyParser.urlencoded({ extended: false }));
    app.use(session({
    secret: "replace this string... k12jh40918e4019u3",
    resave: false,
    saveUninitialized: true,
    cookie: { maxAge: 60 * 60 * 1000 }
    }));

    const backend = express.Router();
    app.use("/server", backend);

    backend.get("/business_employees", (req, res) => {
    res.send([
    { id: 1, nomusu: "Juan Perez", latitud: -0.134655, longitud: -78.465764, codzon: "Zona 1", codemp: "01", codsup: "Juan Perez", tipacc: "T", codalm: "alm01", codcaj: "caj01", establ: "est01", clivis: 145, clipvi: 230 },
    { id: 2, nomusu: "Maria Jacome", latitud: -1.242666, longitud: -78.623333, codzon: "Zona 1", codemp: "01", codsup: "Juan Perez", tipacc: "", codalm: "alm02", codcaj: "caj02", establ: "est02", clivis: 155, clipvi: 120 },
    { id: 3, nomusu: "Daniel Pantoja", latitud: -1.242046, longitud: -78.629262, codzon: "Zona 1", codemp: "01", codsup: "Juan Perez", tipacc: "", codalm: "alm03", codcaj: "caj03", establ: "est03", clivis: 165, clipvi: 270 },
    { id: 4, nomusu: "Carlos Acuña", latitud: -1.266317, longitud: -78.625339, codzon: "Zona 2", codemp: "01", codsup: "Carlos Acuña", tipacc: "", codalm: "alm04", codcaj: "caj04", establ: "est04", clivis: 158, clipvi: 220 },
    { id: 5, nomusu: "Dante Alighieri", latitud: -1.59263, longitud: -79.00098, codzon: "Zona 2", codemp: "01", codsup: "Carlos Acuña", tipacc: "", codalm: "alm05", codcaj: "caj05", establ: "est05", clivis: 115, clipvi: 440 },
    { id: 6, nomusu: "Juan Mesias", latitud: -1.268335, longitud: -78.622616, codzon: "Zona 3", codemp: "01", codsup: "Carlos Acuña", tipacc: "", codalm: "alm06", codcaj: "caj06", establ: "est06", clivis: 153, clipvi: 200 },
    { id: 7, nomusu: "Bryan Torres", latitud: -1.260665, longitud: -78.608434, codzon: "Zona 3", codemp: "01", codsup: "Carlos Acuña", tipacc: "", codalm: "alm07", codcaj: "caj07", establ: "est07", clivis: 35, clipvi: 280 }
    ]);
    });

  • not sure why your code is not working, but in the snippet it works as expected
    https://snippet.webix.com/fgltvbu4

  • edited August 10

    hi @intregal , thanks for your help. I using your code and it works fine, but now I have problem with my map because i can't place my markers in the open map. I add the other link for markers in the html code but it doesn't show the marker in the position I need.
    https://snippet.webix.com/siaqtahv

  • check this
    https://snippet.webix.com/tq3j7pil
    you have to wait for both sellers.waitData and getMap promises.

  • thanks @intregal you're awesome!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!