【发布时间】:2018-12-27 20:41:36
【问题描述】:
我在我的文件中初始化了这些,它位于一个角度应用程序中:
names = ['A','B','C','D'];
const score = [{}];
在做一些检查当前播放器的处理之后,我想为每个播放器创建一个数组。每个玩家的数组都会单独添加。第一个玩家 A,然后是 B,依此类推,直到名称数组中的最后一个玩家被调用,因为他们正在从另一个页面获取分数。 所以,像这样:
{
"A":{
"End#1":{"arrow1": "here the score",
"arrow2": "here the score",
"arrow3": "here the score"
}
},
"B":{
"End#1":{"arrow1": "here the score",
"arrow2": "here the score",
"arrow3": "here the score"
}
},
"C":{
"End#1":{"arrow1": "here the score",
"arrow2": "here the score",
"arrow3": "here the score"
}
},
"D":{
"End#1":{"arrow1": "here the score",
"arrow2": "here the score",
"arrow3": "here the score"
}
}
}
如何动态创建类似 JSON 数组的内容,以便根据名称的数量增加和减少它?另外,怎么可能说名字“A”以后会有第二个结尾,然后我怎么能输入第二个结尾?
这是实现它的整个 Angular 文件...(https://codepen.io/ArcherMArk/pen/ZVJwyQ),希望这个文件有点帮助
【问题讨论】:
-
你能先修复阵列吗?对象数组语法不正确。
-
array.push 和 JSON.parse 应该可以完成工作
-
正确的语法是什么?我是 json 新手,看到人们只在某处使用这样的语法:/ @JaromandaX
-
@JaromandaX 现在有效吗?
-
@JaromandaX 好的,我希望我的语法现在更好;)如何创建这样的数组,因为这是我在脑海中创建的数组,它们应该看起来像。我不知道如何将每个箭头的值添加到正确名称的正确字段中......
标签: javascript arrays json angular