2013-07-30 125 views
0

意圖創建一個js嵌套對象給出語法錯誤。什麼可能導致錯誤?語法錯誤JavaScript嵌套對象

window.thePosts = 
    { 
    'ITEM1': 
     { 
      'SUB1' : 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'} 
      }, 
      'SUB2' : 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'} 
      } 
     }, 
    'ITEM2': 
     { 
      'SUB1' : 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'} 
      }, 
      'SUB2' : 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'} 
      } 
     } 
    }; 
+1

' 'SUB1':'這裏沒有左括號。 – Mics

回答

2

你SUB *是數組,應[]來表示:

window.thePosts = 
    { 
    'ITEM1': 
     { 
      'SUB1' : [ 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'} 
      ], 
      'SUB2' : [ 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'} 
      ] 
     }, 
    'ITEM2': 
     { 
      'SUB1' : [ 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MAKING MONEY','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'} 
      ], 
      'SUB2' : [ 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'}, 
       {'id:':'1','name': 'MARKETING','the_cont': '<img src="/wp-content/assets/images/pop1.jpg">'} 
      ] 
     } 
    };