如何将对象数组值转换为对象中的其他数组值?

时间:2016-07-25 08:19:07

标签: javascript arrays area

我有一个带有地图区域的对象。因为我也将主页区域用于所有其他区域。我想使用某些东西将主页区域引用到所有其他区域,因此代码更易读和更短。 如何使用对象阵列主页进行编辑?因此代码变得更短。像这样的东西_images.edit.areas = _images.homepage.areas?或者我应该在单独的对象中定义主页?

var _images = {
         homepage: {   
            path: 'homepage.jpg',    
            areas: [{      
                coords: '45,143,106,158',   
                text: 'edit',        
                goto: 'edit'       
              }, {
                coords: '45,164,149,180',
                text: 'config',
                goto: 'config' 
              }, {
                coords: '45,181,108,196',
                text: 'setfree',
                goto: 'setfree'
              }]
          },
         edit:{
            path: 'edit.jpg',
            areas: [{     
                coords: '18,131,113,140',  
                text: 'homepage',
                goto: 'homepage'
              }, {
                coords: '45,164,149,180',
                text: 'config',
                goto: 'config'
              }, {
                coords: '45,181,108,196',
                text: 'setfree',
                goto: 'setfree'
              },{ //above everything is like in hompage, below are news areas
             coords: '638,467,652,478',
             text: 'contract',     
             goto: 'contract'
             }]
             },
        }

1 个答案:

答案 0 :(得分:0)

这取决于。通过作业

_images.edit.areas = _images.homepage.areas;

您从hompage进行编辑引用。 eihter主页部分或编辑部分的每个更改都可以在两个对象上使用,因为它们是链接在一起的。

如果你想要,那就没关系 - 但如果没有,那么我建议使用两个独立的对象。

相关问题