1

创建 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">'}
            }
        }
    };
4

1 回答 1

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">'}
            ]
        }
    };
于 2013-07-30T01:36:41.683 回答