Product
인스턴스를 자바 스크립트로 만들고 [webmethod]
을 사용하여 서버에 전달하려고합니다.자바 스크립트에서 객체의 중첩 목록을 만드는 방법
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; }
}
내가
Type
을 만들 수있는하고
및 Foo
하지만 List<Bar>
자바 스크립트 : 다음
[WebMethod]
public static void SetProduct(Product product)
{
// i want a product instance
}
는 Product
내가 만들려고 해요 클래스 (이상 코드에 내 의견을 참조 세부 사항)
자바 스크립트
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) + "}",
});
}
_ "나는 데 덮지 않는 무엇 블레 "라고? 질문이 뭐야? – Madbreaks
코드의 내 의견을 참조하십시오. – user829174