我使用knockoutJS,当我使用“fromJS”时出现以下错误
TypeError:无法调用未定义的方法“fromJS”
我的 JavaScript 代码
<script src="../../Scripts/jquery-1.8.3.js" type="text/javascript"></script>
<script src="../../Scripts/knockout-2.1.0.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var PersonModel = function (data) {
ko.mapping.fromJS(data, {}, this);
};
var data = $.getJSON("http://localhost:40913/candidate/index/1", function (data)
{
viewModel = new PersonModel(data);
ko.applyBindings(viewModel);
}
);
});
</script>
JSON 输出
{ PersonalInfo: { PTitle: null, PGender: { Id: 1, Name: "Male", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, PMilitaryService: { Id: 2, Status: "Exempted", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, PMarital: { Id: 2, Status: "Engaged", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, PNationality: { Id: 1, NationalityName: "Egyptian", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, Id: 1, FirstName: "Jason", SecondName: "J", ThirdName: "Patrick", FourthName: "Jules", BirthDate: "2013-01-01T00:00:00", GenderId: 1, MilitaryServiceId: 2, MaritalId: 2, NationalityId: 1, IsDeleted: null, LastModified: "2013-01-21T13:32:20.437", ModifiedBy: null, FullName: "fhfghfghfghgfhg" }, TraineeInfo: null, AdressInfo: { PCity: { Id: 6, Name: "Cairo", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, PCountry: { Id: 1, Name: "France", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, Id: 1, Street: "5th Ave", District: "6th Area", CityId: 6, CountryId: 1, IsDeleted: null, LastModified: "2013-01-21T13:32:20.437", ModifiedBy: null }, ContactInfo: { Id: 1, PhoneNumber: "12345678", MobileNumber: "2012415413", Email: "a@b.com", EmailConfirm: null, IsDeleted: null, LastModified: "2013-01-21T13:32:20.437", ModifiedBy: null }, HighSchool: { PSchoolCertificate: { Id: 1, Name: "Thanwya Amma", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, Id: 1, Name: "El Nasr School", SchoolCertificateId: 1, GraduationYear: "2013-01-10T00:00:00", OverallGrade: 90, OtherSchoolCertificate: null, IsDeleted: null, LastModified: "2013-01-21T13:32:20.437", ModifiedBy: null }, Type: { Id: 1, Type: "Fresh Graduate", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, Certifications: [ ], TrainingCourses: [ ], CareerHistories: [ ], Universities: [ { PCertificate: { Id: 1, CertificateType: "BACHELOR", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, PUniversityName: { Id: 2, Name: "ABBASSIA", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, PFaculty: { Id: 1, Name: "ACCOUNTING", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, PSpecialization: { Id: 2, Name: "ACCOUNTING ENGLISH", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, PGrade: { Id: 3, OverallGrade: "Very Good", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, Id: 1, CertificateId: 1, OtherCertificate: null, UniversityNameId: 2, OtherUniversity: null, FacultyId: 1, OtherFaculty: null, SpecializationId: 2, OtherSpecialization: null, GraduationYear: "2013-01-04T00:00:00", GradeId: 3, IsDeleted: null, LastModified: "2013-01-21T13:32:20.437", ModifiedBy: null } ], Languages: [ { PLangName: { Id: 1, Name: "English", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, PLangProf: { Id: 4, LanguageProf: "Native", IsDeleted: false, LastModified: "2013-01-21T00:00:00", ModifiedBy: "System Auto Generated" }, Id: 1, LangNameId: 1, LangProfId: 4, IsDeleted: null, LastModified: null, ModifiedBy: null } ], TestInfo: null, InterviewInfo: null, TechnicalInterview: null, MedicalTest: null, SecuirtyTest: null, HREmployee: null, Id: 1, Ssid: "28454654654545", SsidConfirm: null, Status: null, StatusId: 1, RefCode: "8951000000", ApplicationTypeId: 1, EntryDate: "2013-01-21T13:32:20.437", Skills: "aaksdklasdjkl asd asd d d d g ghs fgdsfgd", Photo: null, IsDeleted: null, LastModified: "2013-01-21T13:32:20.437", ModifiedBy: null }