这是一个不错的夜间项目,但实际上我有些头疼。JS - 如何用字符串等对象构建动态嵌套对象
我需要的就是这样的例子功能:
result = set("itemCategories[0].items[0].name", "Test")
应返回:
{ itemCategories: [
{
items: [ {name: "Test"} ]
}
}]
...在给定的属性的情况下,“itemCategories [1] .items [ 2]。名称”这样的结果:
{ itemCategories: [
null,
{
items: [
null,
null,
{name: "Test"}
]
}
}]
您应该能[解决方案在这里]适应(https://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key)至去做。 –
为什么你需要传递一个字符串?为什么不瞄准只是做itemCategories [0] .items [0] .name =“Test”? – Shard
@Shard该字符串是从另一个系统给出的 – Chilian