如何在javascript中解析这个对象? [英] How to parse this object in javascript?

查看:91
本文介绍了如何在javascript中解析这个对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于MVC的Web应用程序,其中对象myMap是Map< integer,object>我填充到Controller中,然后传递给View。我如何解析它?

当我运行应用程序时,我可以在视图中看到这个:

I have a web application,based on MVC, where the object "myMap" is a Map<integer,object> that i populate into Controller and i pass to the View. How can i parse it?
When i run application, i can see this in the view:

<pre lang="Javascript">
var myMap ={0:{'cellId':'15064','creationTime':null,'date':'20120528','direction':'O','id':null,'localAreaCode':'20016','modificationTime':null,'receiver':'URkatij09Kce/Qj0vnEr8s','sender':'VdzW4Vvb7IcjURYCGBs.Is','siteName':'NAVIGLIO PAVESE','time':'222932','version':0},
1:{'cellId':'15064','creationTime':null,'date':'20120528','direction':'O','id':null,'localAreaCode':'20016','modificationTime':null,'receiver':'URkatij09Kce/Qj0vnEr8s','sender':'VdzW4Vvb7IcjURYCGBs.Is','siteName':'CERMENATE','time':'222932','version':0}};
</pre>



如何获得与密钥相关的值? (例如每个键的SiteName值)谢谢



我尝试过:




How can i get values associated to a key? (for example SiteName value for every key) Thank you

What I have tried:

for (var m in myMap){
      for (var i=0;i<myMap[m].length;i++){

   geocoder.geocode({'address': myMap[m][i]}, function(results, status) {
     if (status === 'OK') {
           resultsMap.setCenter(results[0].geometry.location);
           var marker = new google.maps.Marker({
            map: resultsMap,
            position: results[0].geometry.location
           });

     } else {
       alert('Geocode was not successful for the following reason: ' + status);
     }
   });
   }
 }

推荐答案

myMap[m]

据我所知,这不是一个数组。

所以这个;

Is not an array as far as I can tell.
So this;

for (var i=0;i<myMap[m].length;i++){



韩元不行。

写下调试器;在你的第一个循环中的代码。

这将改变你的世界。


Won't work.
Write the word debugger; in you're code inside first loop.
It will change you're world.


这篇关于如何在javascript中解析这个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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