jQuery.each()如何使用关联数组(对象)? [英] How does jQuery.each() work with associative arrays (objects)?

查看:118
本文介绍了jQuery.each()如何使用关联数组(对象)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关联数组,里面有两个对象。通过 $(myassoc).each()运行,回调只运行一次。此外,回调参数(索引和对象)分别返回0和整个关联数组。

I have an associative array with two object inside. Running this through $(myassoc).each(), the callback runs only once. Also the callback parameters (index and object) returns 0 and the entire associative array, respectively.

可以预期 jQuery.each()为数组中的每个元素运行,返回正确的键作为索引,将正确的元素作为对象返回。

One would expect jQuery.each() to run for each element in the array, returning the correct keys as index and the correct element as the object.

为什么不发生这种情况,并且jQuery可以做我想要的事情吗?

Why isn't that happening, and can jQuery do what I'm after?

推荐答案

我认为你正在寻找 jQuery.each()而不是.each()

I think you're looking for jQuery.each() instead of .each()

试试这个:

    $.each(myassoc, function(index, value){
      //your code
    });

这篇关于jQuery.each()如何使用关联数组(对象)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆