2016-07-25 17 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; 

あなたは編集のために参照を作成します。 eihterホームページ部分または編集部分のすべての変更は、リンクされているため両方のオブジェクトで利用できます。

あなたがそれを望むなら、それはいいですが、そうでなければ、私は2つの独立したオブジェクトを使うことを提案します。

+1

ありがとうございます。さて、私はそれらを分けるでしょう^^ – Emloy

関連する問題