【问题标题】:Prototype Js : How to iterate over some of the Json objects [duplicate]Prototype Js:如何迭代一些 Json 对象 [重复]
【发布时间】:2013-11-03 09:23:32
【问题描述】:

如何在Prototype Js(不是Jquery)中迭代这种Json对象

还有带有值索引的子对象

我想用给定的值填充多选框。

data = object(
    0 => object(
        'label' = > 'test1',
        'value' = > 1
    ),
    1 => object(
        'label' = > 'test1',
        'value' = >
        0 = > object(
            'label' = > 'sub testing1',
            'value' = > 1
        ),
        1 = > object(
            'label' = > 'sub testing2',
            'value' = > 1
        ),
    ),
    3 = > object(
        'label' = > 'test3',
        'value' = >
        0 = > object(
            'label' = > 'sub testing - test 3',
            'value' = > 33
        ),
    )
)

【问题讨论】:

    标签: javascript json prototypejs


    【解决方案1】:

    我有一段时间没有使用 Prototype,但试试这个:

    data.each(function(i){
        console.log(i.label); // or whatever you need to do
    });
    

    【讨论】:

    • 我不想要一行代码。我想解析值和标签来填充多选。
    • 所以继续写代码吧。我们不会为您完成所有工作。
    • 别无礼。好的?你明白吗?
    • 我没有要求你这样做。好的。迷路
    • @ShahidNajamAfridi - 你明白这段代码完全符合你的要求。你才是粗鲁的人。
    猜你喜欢
    • 2021-10-23
    • 1970-01-01
    • 2017-05-21
    • 2019-07-21
    • 1970-01-01
    • 2018-06-30
    • 1970-01-01
    • 2014-04-16
    • 2016-01-25
    相关资源
    最近更新 更多