How to create nested list of objects in javascript

rory

New Member
I am trying to create \[code\]Product\[/code\] instance in Javascript and than to pass it to the server using \[code\][webmethod]\[/code\].\[code\][WebMethod]public static void SetProduct(Product product){ // i want a product instance }\[/code\]Following is \[code\]Product\[/code\] class that i'm trying to create:\[code\]public class Product{ public Type Type { get; set; } public Foo Foo { get; set; } public List<Bar> Bars { get; set; }}public class Type{ public string ID { get; set; }}public class Foo{ public string ID { get; set; } public string Color { get; set; }}public class Bar{ public string Name { get; set; }}\[/code\]I am being able to create \[code\]Type\[/code\] and \[code\]Foo\[/code\] but not \[code\]List<Bar>\[/code\] in Javascript: (see my comments in the code for more details)Javascript\[code\]function setProduct() { var product = {}; product.Type = {}; product.Foo = {}; product.Type.ID = 'typeID'; product.Foo.ID = 'fooID'; product.Foo.Color = 'fooColor'; //here is my question how can create List<Bar> Bars and add it to product item??? $.ajax({ type: "POST", url: "Default.aspx/SetProduct", contentType: "application/json; charset=utf-8", dataType: "json", async: false, data: "{product:" + JSON.stringify(product) + "}", });}\[/code\]
 
Back
Top