2016-07-25 86 views
2

我有一个地图区域的对象。因为我也为所有其他领域使用主页区域。我想用一些东西将主页区域引用到所有其他区域,因此代码更具可读性和更短。 如何使用对象数组主页进行编辑?所以代码变得更短。像这样_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' 
      }] 
      }, 
     } 

回答

0

这取决于。随着作业

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

你从hompage参考编辑。在主页部分或编辑部分的每个变更都可以在两个对象上使用,因为它们是链接在一起的。

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

+1

好的,谢谢。那么,我会分开他们^^ – Emloy