【发布时间】:2011-12-04 20:16:23
【问题描述】:
这是我正在使用的对象的简短示例。
{
"myservices": [
{
"name": "oozie",
"hostidn": "1",
"details": "failed process health monitor....",
"currstatus": "Warning",
"currstatusclass": "warning"
},
{
"name": "oozie",
"hostidn": "2",
"details": "failed process health monitor....",
"currstatus": "Warning",
"currstatusclass": "warning"
},
{
"name": "oozie",
"hostidn": "3",
"details": "failed process health monitor....",
"currstatus": "Warning",
"currstatusclass": "warning"
},
{
"name": "oozie",
"hostidn": "4",
"details": "failed process health monitor....",
"currstatus": "Warning",
"currstatusclass": "warning"
},
{
"name": "oozie",
"hostidn": "5",
"details": "failed process health monitor....",
"currstatus": "Warning",
"currstatusclass": "warning"
},
{
"name": "single-namenode",
"hostidn": "2",
"details": "failed process health monitor....",
"currstatus": "Warning",
"currstatusclass": "warning"
}
]
}
我最终想在运行所有这些并显示它们之前找到最高的“hostid”是什么。 hostidn 是第 N 个数字,它可以是唯一的数字,也可以是数百个深度,中间有多个重复。我的目标是找到最高的一个,并在此基础上对其执行 for 或 while 循环,以在可视化显示中将它们组合在一起。示例通知我在下面有一个带有数字 2 的 hostidn,而其余的都有自己的。我想将两者与 2 组合在一个框中以进行显示,但在这种情况下有 5 个不同的 hostidn。我不知道也许我想错了,不过我会接受建议。
【问题讨论】:
-
是你想显示所有具有最高hostid的问题,包括欺骗?
-
你想得到最高的数字还是出现次数最多的数字?无论如何,您必须遍历数组并比较数字,那么您的实际问题是什么?
-
嗯,基本上我想显示所有的,包括基于 hostidn 的欺骗。在这种情况下,hostid 将充当一个容器,然后将在该容器中显示每个具有相同 hostidn 的容器。这里的问题是 hostidn 可以是 1 到 200+ 之间的任何值,所以我没有设置的数字可以使用。另一个问题是它们在对象中输出的方式是说随机性最小所以我必须找到最高的数字,这样我才能运行一段时间,比如基于从低到高的循环,这些数字将永远是为了我的知识意味着没有计数的差距。我只是不知道高数是多少
标签: javascript jquery json sorting object