在NUXT应用程序中,控制台超出一定级别的嵌套返回未定义的量。如何达到深嵌套的元素?
在NUXTJS应用程序中,我正在尝试访问Arcgis地图提供的传奇中的DIV。该div嵌套在我的地图元素中。我给了地图元素一个ref 地图
为了达到它。
<template>
<div id="viewDiv" ref="map" class="h-full"></div>
</template>
该控制台日志
console.log(
'inTheMap?',
this.$refs.map.children[0].children[2].children[0].children[1]
.children[0]
)
将返回DIV,但我想达到的DIV更深。不幸的是,如果我委托log更深一个级别(如果我添加.children [0]
),则控制台.log返回undfection
。我的问题:我们可以安装多深的嵌套元素有限制吗?如果是,是否有另一种方法可以达到深嵌套元素?
这是地图的代码(一部分):
<template>
<div id="viewDiv" ref="map" class="h-full"></div>
</template>
<script>
import Map from '@arcgis/core/Map'
import MapView from '@arcgis/core/views/MapView'
import esriConfig from '@arcgis/core/config'
import FeatureLayer from '@arcgis/core/layers/FeatureLayer'
import Legend from '@arcgis/core/widgets/Legend'
import Search from '@arcgis/core/widgets/Search'
export default {
props: {
selectedTab: {
type: Number,
default: 3,
},
},
data() {
return {
project:
'https://...',
countries:
'https://...',
projectLyr: undefined,
countryLyr: undefined,
searchWidget: undefined,
legend: undefined,
map: undefined,
view: undefined,
fieldName: 'composite_risk',
renderer: {},
filter: "dev_type = 'road and railway'",
impactId: 0,
hasKmField: true,
buttonDescription: 'Total Environmental Risk',
legendSymbol: [],
}
},
mounted() {
esriConfig.apiKey =
'myToken'
this.map = new Map({ basemap: 'osm-light-gray' })
this.view = new MapView({
map: this.map,
center: [15, 50],
zoom: 3,
container: 'viewDiv',
})
this.projectLyr = new FeatureLayer({
url: this.project,
outFields: ['*'],
title: 'Legend',
})
this.countryLyr = new FeatureLayer({
url: this.countries,
outFields: ['*'],
title: 'Legend',
})
this.view.popup = {
dockOptions: {
position: 'bottom-left',
},
}
this.legend = new Legend({
view: this.view
})
this.view.ui.add(this.legend, 'top-right')
this.updateLayer({
value: 'composite_risk',
hasKmField: true,
title: 'Total Environmental Risk',
})
},
methods: {
updateLayer(value) {
if (typeof value === 'number') {
this.filter =
value === 1
? "dev_type = 'road' OR dev_type = 'railway'"
: "dev_type = 'road and railway'"
value = {
value: 'composite_risk',
hasKmField: true,
title: 'Total Environmental Risk',
}
this.view.popup.close()
this.impactId = 0
}
if (!value.isFilter) {
this.fieldName = value.value
this.hasKmField = value.hasKmField
this.buttonDescription = value.title
} else {
this.filter = `${value.value}`
}
this.$nextTick(() => {
if (this.selectedTab === 0) {
this.map.remove(this.projectLyr)
this.map.add(this.countryLyr)
this.filtering(value)
} else {
this.map.remove(this.countryLyr)
this.map.add(this.projectLyr)
this.filtering(value)
}
this.layer.popupTemplate =
this.selectedTab === 0
? this.popupTemplateCountry
: this.popupTemplateProject
})
console.log(
'inTheMap?',
this.$refs.map.children[0].children[2].children[0].children[1]
.children[0]
)
},
}
In a nuxtjs application I am trying to access a div in a legend provided by a map from ArcGIS. This div is nested quite deeply in my map element. I gave the map element a ref map
in order to reach it.
<template>
<div id="viewDiv" ref="map" class="h-full"></div>
</template>
This console log
console.log(
'inTheMap?',
this.$refs.map.children[0].children[2].children[0].children[1]
.children[0]
)
will return a div but the div that I want to reach is nested deeper. Unfortunately if I console.log just one level deeper (if I add .children[0]
), the console.log returns undefined
. My question: is there a limit to how deep we can console.log nested elements ? If yes, is there another way to reach deeply nested elements ?
This is (part of) the code for the map:
<template>
<div id="viewDiv" ref="map" class="h-full"></div>
</template>
<script>
import Map from '@arcgis/core/Map'
import MapView from '@arcgis/core/views/MapView'
import esriConfig from '@arcgis/core/config'
import FeatureLayer from '@arcgis/core/layers/FeatureLayer'
import Legend from '@arcgis/core/widgets/Legend'
import Search from '@arcgis/core/widgets/Search'
export default {
props: {
selectedTab: {
type: Number,
default: 3,
},
},
data() {
return {
project:
'https://...',
countries:
'https://...',
projectLyr: undefined,
countryLyr: undefined,
searchWidget: undefined,
legend: undefined,
map: undefined,
view: undefined,
fieldName: 'composite_risk',
renderer: {},
filter: "dev_type = 'road and railway'",
impactId: 0,
hasKmField: true,
buttonDescription: 'Total Environmental Risk',
legendSymbol: [],
}
},
mounted() {
esriConfig.apiKey =
'myToken'
this.map = new Map({ basemap: 'osm-light-gray' })
this.view = new MapView({
map: this.map,
center: [15, 50],
zoom: 3,
container: 'viewDiv',
})
this.projectLyr = new FeatureLayer({
url: this.project,
outFields: ['*'],
title: 'Legend',
})
this.countryLyr = new FeatureLayer({
url: this.countries,
outFields: ['*'],
title: 'Legend',
})
this.view.popup = {
dockOptions: {
position: 'bottom-left',
},
}
this.legend = new Legend({
view: this.view
})
this.view.ui.add(this.legend, 'top-right')
this.updateLayer({
value: 'composite_risk',
hasKmField: true,
title: 'Total Environmental Risk',
})
},
methods: {
updateLayer(value) {
if (typeof value === 'number') {
this.filter =
value === 1
? "dev_type = 'road' OR dev_type = 'railway'"
: "dev_type = 'road and railway'"
value = {
value: 'composite_risk',
hasKmField: true,
title: 'Total Environmental Risk',
}
this.view.popup.close()
this.impactId = 0
}
if (!value.isFilter) {
this.fieldName = value.value
this.hasKmField = value.hasKmField
this.buttonDescription = value.title
} else {
this.filter = `${value.value}`
}
this.$nextTick(() => {
if (this.selectedTab === 0) {
this.map.remove(this.projectLyr)
this.map.add(this.countryLyr)
this.filtering(value)
} else {
this.map.remove(this.countryLyr)
this.map.add(this.projectLyr)
this.filtering(value)
}
this.layer.popupTemplate =
this.selectedTab === 0
? this.popupTemplateCountry
: this.popupTemplateProject
})
console.log(
'inTheMap?',
this.$refs.map.children[0].children[2].children[0].children[1]
.children[0]
)
},
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了达到元素,您可以从传说的
容器
节点开始。这是一个逐步的代码样本,以获取欲望元素。为了简化而没有检查。
hide
类只是为此起作用的一件事是,
Legend
需要在屏幕上显示。在搜索要隐藏的div
元素之前,您需要一个策略来确保此问题。In order to reach the element you can start on the
container
node of the legend.This is a step by step code sample in order to get to the desire element. There is no exist checks in order to simplify.
hide
class is just,Now, one thing in order for this to work is that the
legend
needs to be display on screen. You need an strategy to secure this before searching for thediv
element to hide.