Abhishek
Abhishek

Reputation: 173

jquery array of objects

Hi I am new to 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}]

and that is what I am looking for

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}]
    }

Is it possible in jquery?

Upvotes: 0

Views: 114

Answers (2)

Ronald Borla
Ronald Borla

Reputation: 586

It's not really jQuery, though jQuery use JSON most of the time, but this one is simply JSON, an object in Javascript. Just create a function which can sort things out. In fact, you don't need any jQuery at all for this type of job.

Upvotes: 0

Johan
Johan

Reputation: 35194

Nested objects?

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

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

Upvotes: 1

Related Questions