创建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">'}
}
}
};
答案 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">'}
]
}
};