【发布时间】:2019-12-17 09:16:42
【问题描述】:
我在数组中有嵌套对象,我想用 javascript 将它们转换为点符号字符串。
这是我用于转换过程的数据示例数据。
[
{
property: 'name',
children: [],
message: 'name should not be empty',
},
{
property: 'priceForm',
children: [
{
property: 'priceCurrency',
children: [],
message: 'priceCurrency should not be empty',
},
],
},
{
property: 'priceForm',
children: [
{
property: 'rolePrices',
children: [
{
property: '0',
children: [
{
property: 'markupType',
children: [],
message: 'markupType should not be empty',
},
],
},
],
},
],
},
]
预期结果是
{
'name': 'name should not be empty',
'priceForm.priceCurrency': 'priceCurrency should not be empty',
'priceForm.rolePrices.0.markupType': 'markupType should not be empty',
}
【问题讨论】:
-
如果
children中的元素超过 1 个会怎样? -
例如 'priceForm.rolePrices.0.markupType1': 'markupType1 不应为空', 'priceForm.rolePrices.1.markupType2': 'markupType2 不应为空', 'priceForm.rolePrices .2.markupType3': 'markupType3 不能为空'
标签: javascript arrays object multidimensional-array nested