简体   繁体   English

遍历jquery对象以获取其值

[英]Cycling through jquery object to get its values

I have to loop through the object and get all its values. 我必须遍历该对象并获取其所有值。 Here's an image of object 这是物体的图像 在此处输入图片说明
So, basically i have to get classificatorCodeId and loop through observationList to get its child classificatorCodeId's and observationLists, and so on. 因此,基本上,我必须获取classificatorCodeId并遍历observationList以获取其子classificatorCodeId和observationLists,依此类推。
If you guys have any ideas, what's the best way to loop through this object, id be happy to try your solutions. 如果您有任何想法,循环遍历此对象的最佳方法是什么,请尝试尝试解决方案。

Following code will print all values in that object as key --> value pairs 以下代码将该对象中的所有值打印为键->值对

var traverse = function(mainObject)
{
  $.each(mainObject, function(index, subObject)
  {
    if(($.type(subObject) === "object" || $.type(subObject) === "array"))
    {
      traverse(subObject);
    }
    else
    {
      console.log(index+" --> "+subObject);
    }
  });
}

traverse(mainObject);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM