@danilr

Как в метод передать событие(e) и какой-то свой параметр?

В компоненте есть метод, туда надо вместо this.residentials подставлять соответствующие значения, которые я должен туда передать. Передается событие(нужное, убирать нельзя) и надо как-то мой массив пробросить, Но как это сделать?
onZoomEnd(e) {
			const { oldZoom } = this,
				newZoom = this.map.getZoom();

			const template =
				oldZoom > this.switchOnZoom && newZoom <= this.switchOnZoom
					? this.setMiniMarker
					: oldZoom <= this.switchOnZoom && newZoom > this.switchOnZoom
					? this.setZoomMarker
					: null;
			if (template) {
				Object.values(this.markers._layers).forEach((marker, i) => {
					marker._icon.innerHTML = template(this.residentials[i]);
				});
			}
		},

mounted() {
		this.markers = DG.featureGroup();
		this.popups = DG.featureGroup();

		this.map = DG.map("map", {
			center: [54.98, 82.89],
			zoom: 13,
			minZoom: 7,
			zoomControl: false,
			fullscreenControl: false
    });
    
      this.dataRequest.then(response => {
        this.setMarkers(this.residentials)
        console.log(this.residentials);
        
        this.map.on("zoomstart", this.onZoomStart);
		    this.map.on("zoomend", this.onZoomEnd);
        
			})
			.catch(error => console.log(error));

	},
  • Вопрос задан
  • 85 просмотров
Решения вопроса 1
yarkov
@yarkov Куратор тега JavaScript
Помог ответ? Отметь решением.
Перенес из комментариев в ответы
-------------------------------------------
Вызываем метод так:
this.map.on("zoomend", () => this.onZoomEnd(МАССИВ));

И измененный код метода:
onZoomEnd(residentials) {
  const { oldZoom } = this,
    newZoom = this.map.getZoom();

  const template =
    oldZoom > this.switchOnZoom && newZoom <= this.switchOnZoom
      ? this.setMiniMarker
      : oldZoom <= this.switchOnZoom && newZoom > this.switchOnZoom
      ? this.setZoomMarker
      : null;
  if (template) {
    Object.values(this.markers._layers).forEach((marker, i) => {
      marker._icon.innerHTML = template(residentials[i]);
    });
  }
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы