{
noteCount_xxx:
{
favorite:"favorite-border",
id:"noteCount_xxx",
note:"noteContent",
title: "notetitle",
}
}
Run Code Online (Sandbox Code Playgroud)
noteCount_xxx是动态的输出将是
{favorite:"favorite-border",id:"noteCount_xxx",注意:"noteContent",标题:"notetitle"}
我无法从动态节点获取数据,获取该数据的最佳方法是什么?
您可以使用Object.keys来查找nodeCount_xxx值:
const yourJSON = {
noteCount_xxx: {
favorite:"favorite-border",
id:"noteCount_xxx",
note:"noteContent",
title: "notetitle",
}
}
const firstKey = Object.keys(yourJSON)[0]
console.log(yourJSON[firstKey])Run Code Online (Sandbox Code Playgroud)
或者如果你已经知道了它的价值nodeCount_xxx,那么简单地访问你的对象:
yourJSON[noteCount]