javascript - 从 javascript 中的另一个对象访问嵌套属性
问题描述
我对下面的代码如何访问嵌套属性感到困惑。该addLayer
函数接受一个对象,该对象具有textfield
来自上述addSource
方法的嵌套属性properties.storeId
。我对如何textfield
写成{storeId}
. 该对象在任何地方都没有被破坏,因此它怎么能这样写?
const loadmap = () => {
map.on("load", () => {
map.addSource("point", {
type: "geojson",
data: {
type: "FeatureCollection",
features: [
{
type: "Feature",
geometry: {
type: "Point",
coordinates: [-71.157895, 42.707741],
},
properties: {
storeId: "0001",
icon: "store"
},
},
],
},
});
map.addLayer({
id: "points",
type: "symbol",
source: "point", // reference the data source
layout: {
"icon-image": "airfield-11", // reference the image
"text-field": "{storeId}",
},
});
});
};
解决方案
双引号之间的 {storeId} 只是一个字符串,
否则它是
let object={storeId:storeId}
另一个例子:
let name="erfan"
let obj = {name} /// equivalent to {name:name}
推荐阅读
- c# - 无法找到 ArgumentException 的根本原因
- c# - 字符串拆分函数如何在 C# 内部工作?
- java - 为什么此照明代码仅适用于单个灯并且在我添加多个灯时会中断?
- regex - Perl 正则表达式作为用户搜索输入(清理)
- javascript - 无法在某些文件夹中执行 fs.write 操作
- c# - 使用 access 数据库中的数据填充列表
- android - 无法从“使用 google plus 登录”中的 google 状态获取数据
- git - git:如何在变基后合并或变基?
- javascript - 如何按值对对象数组进行分组
- python - 如何使用 Python 从 Azure Functions 中的辅助线程重定向日志