第一篇文章... 通常我能够搜索并找到我的问题的答案,但这次我不能。我有一个使用一堆其他对象的对象:
[DataContract]
public class CoolStuff
{
[DataMember]
public Field[] CoolField { get; set; }
public CoolStuff()
{
CoolField = SetCoolField();
}
private Field[] SetCoolField()
{
return new Field[]
{
new Field("Project Information", "ProjectInformation"),
new Field("Resource Information", "ResourceInformation"),
}
}
}
[DataContract]
public class Field
{
[DataMember]
public string Prompt { get; set; }
[DataMember]
public string Value { get; set; }
[DataMember]
public bool IsLocked { get; set; }
public Field(string prompt, string value = "n/a", bool isLocked = false)
{
Prompt = prompt;
Value = value;
IsLocked = isLocked;
}
}
我从服务中调用我的构造函数,当我尝试使用 $.getJSON(/Service.svc/coolstuff/' + id, loadCoolStuff);
问题是,当我让我的 Field 类从另一个类继承时,.getJson 调用失败而没有真正给我一个原因。
[DataContract]
public class CoolStuff
{
[DataMember]
public FieldBase[] CoolField { get; set; }
public CoolStuff()
{
CoolField = SetCoolField();
}
private FieldBase[] SetCoolField()
{
return new FieldBase[]
{
new Field("Project Information", "ProjectInformation"),
new Field("Resource Information", "ResourceInformation"),
}
}
}
[DataContract]
public class FieldBase
{
}
[DataContract]
public class Field : FieldBase
{
[DataMember]
public string Prompt { get; set; }
[DataMember]
public string Value { get; set; }
[DataMember]
public bool IsLocked { get; set; }
public Field(string prompt, string value = "n/a", bool isLocked = false)
{
Prompt = prompt;
Value = value;
IsLocked = isLocked;
}
}
有人可以解释为什么使用 ^ 这段代码,我对 .getJSON 的调用失败了吗?我真的被困在这里了。非常感谢!