jquery对象数组

时间:2012-02-21 09:21:46

标签: jquery json

嗨,我是jquery的新手

var sales = [{CategoryName="colddrink",ProductName="coke", SaleMonth="Feb ",    CategoryId=1},
{ CategoryName="colddrink",ProductName="pepsi" ,SaleMonth="Feb ", CategoryId=1}     {CategoryName="Snacks", ProductName="nuts",SaleMonth="Dec", CategoryId=32},
         {CategoryName="colddrink",ProductName="pepsi", SaleMonth="Mar ", CategoryId=1},
         {CategoryName="Snacks",ProductName="popcorn", SaleMonth="Feb ", CategoryId=32}]

这就是我要找的东西

var sales = { "colddrink" :[{ProductName="coke", SaleMonth="Feb ", CategoryId=1},
            {ProductName="pepsi" ,SaleMonth="Feb ", CategoryId=1},
            {ProductName="pepsi", SaleMonth="Mar ", CategoryId=1}],

    "Snacks"  :[{ProductName="nuts",SaleMonth="Dec", CategoryId=32},
            {ProductName="popcorn", SaleMonth="Feb ", CategoryId=32}]
    }

在jquery中可以吗?

2 个答案:

答案 0 :(得分:1)

嵌套对象?

var sales = {
    cooldrink : {
        productname: 'coke',
        salemonth: 'feb'
    },
    snacks: {
        productname: 'nuts',
        salemonth: 'dec'
    }
};

alert(sales.cooldrink.productname);​ //coke

答案 1 :(得分:0)

这不是真正的jQuery,虽然jQuery大多数时候都使用JSON,但这只是JSON,Javascript中的一个对象。只需创建一个可以解决问题的功能。事实上,对于这类工作,你根本不需要任何jQuery。