【问题标题】:How to get object array values to other array values within the object?如何将对象数组值获取到对象内的其他数组值?
【发布时间】:2016-07-25 08:19:06
【问题描述】:

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

【问题讨论】:

    标签: javascript arrays area


    【解决方案1】:

    这取决于。随着任务

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

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

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

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 2022-10-23
      • 1970-01-01
      • 2019-07-29
      • 2021-06-04
      • 1970-01-01
      • 2019-10-17
      • 2021-08-17
      • 1970-01-01
      相关资源
      最近更新 更多