本文介绍了KnockoutJS fromJS无法正常工作TypeError:无法调用未定义的方法'fromJS'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用基因敲除JS,当我使用"fromJS"时出现以下错误
I use knockoutJS and i had the following error when i use "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: "[email protected]",
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
}
推荐答案
从
https://raw.github.com/SteveSanderson/knockout.mapping/master/build/output/knockout.mapping-latest.js
并通过以下方式添加它:
and add it via:
<script src="../../Scripts/knockout.mapping-latest.js" type="text/javascript"></script>
这篇关于KnockoutJS fromJS无法正常工作TypeError:无法调用未定义的方法'fromJS'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!