语法错误JavaScript嵌套对象

时间:2013-07-30 01:33:30

标签: javascript

创建js嵌套对象的意图是语法错误。可能导致错误的原因是什么?

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 个答案:

答案 0 :(得分: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">'}
            ]
        }
    };