繁体   English   中英

如何获取对象数组值到对象中的其他数组值?

[英]How to get object array values to other array values within the object?

我有一个带有地图区域的对象。 因为我也将主页区域用于所有其他区域。我想使用一些东西来将主页区域引向所有其他区域,因此代码更易读且更短。 如何使用对象数组主页进行编辑? 因此,代码变得更短了。 _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'
             }]
             },
        }

这取决于。 与任务

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

您从hompage进行参考以进行编辑。 在首页和编辑部分的每个更改都可在两个对象上使用,因为它们链接在一起。

如果您愿意,那很好-但是,如果不行,我建议使用两个独立的对象。

暂无
暂无

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

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