gpt4 book ai didi

javascript - KnockoutJS fromJS 不工作 TypeError : Cannot call method 'fromJS' of undefined

转载 作者:数据小太阳 更新时间:2023-10-29 04:26:25 25 4
gpt4 key购买 nike

我使用 knockoutJS,当我使用“fromJS”时出现以下错误

TypeError: Cannot call method 'fromJS' of undefined

我的 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
}

最佳答案

从中获取插件

https://raw.github.com/SteveSanderson/knockout.mapping/master/build/output/knockout.mapping-latest.js

并通过以下方式添加:

<script src="../../Scripts/knockout.mapping-latest.js" type="text/javascript"></script>

关于javascript - KnockoutJS fromJS 不工作 TypeError : Cannot call method 'fromJS' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14441276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com